This contract is responsible for the scheduled distribution of emissions based on predefined cycles and decay settings.
Manages the periodic distribution of B3TR tokens to XAllocation, Vote2Earn, and Treasury allocations. This contract leverages openzeppelin’s AccessControl, ReentrancyGuard, and UUPSUpgradeable libraries for access control, reentrancy protection, and upgradability.
bytes32 MINTER_ROLE
Role for addresses allowed to mint new tokens
bytes32 UPGRADER_ROLE
Role for addresses that can upgrade the contract
bytes32 CONTRACTS_ADDRESS_MANAGER_ROLE
The role that can set external contracts addresses
bytes32 DECAY_SETTINGS_MANAGER_ROLE
Role for addresses that can update the decay settings
uint256 SCALING_FACTOR
event EmissionDistributed(uint256 cycle, uint256 xAllocations, uint256 vote2Earn, uint256 treasury)
Emitted when emissions are distributed for a cycle
event XAllocationsAddressUpdated(address newAddress, address oldAddress)
Emitted when XAllocations address is updated
event Vote2EarnAddressUpdated(address newAddress, address oldAddress)
Emitted when Vote2Earn address is updated
event XAllocationsGovernorAddressUpdated(address newAddress, address oldAddress)
Emitted when XAllocationsGovernor address is updated
event TreasuryAddressUpdated(address newAddress, address oldAddress)
Emitted when Treasury address is updated
event EmissionCycleDurationUpdated(uint256 newDuration, uint256 oldDuration)
Emitted when the emission cycle duration is updated
event XAllocationsDecayUpdated(uint256 newDecay, uint256 oldDecay)
Emitted when the xAllocations decay rate is updated
event Vote2EarnDecayUpdated(uint256 newDecay, uint256 oldDecay)
Emitted when the vote2Earn decay rate is updated
event Vote2EarnDecayPeriodUpdated(uint256 newPeriod, uint256 oldPeriod)
Emitted when the vote2Earn decay period is updated
event MaxVote2EarnDecayUpdated(uint256 newDecay, uint256 oldDecay)
Emitted when the max vote2Earn decay rate is updated
event XAllocationsDecayPeriodUpdated(uint256 newPeriod, uint256 oldPeriod)
Emitted when the xAllocations decay period is updated
event TreasuryPercentageUpdated(uint256 newPercentage, uint256 oldPercentage)
Emitted when the treasury percentage is updated
Initialization data for the Emissions contract
struct InitializationData {
address minter;
address admin;
address upgrader;
address contractsAddressManager;
address decaySettingsManager;
address b3trAddress;
address[4] destinations;
uint256 migrationAmount;
uint256 initialXAppAllocation;
uint256 cycleDuration;
uint256[4] decaySettings;
uint256 treasuryPercentage;
uint256 maxVote2EarnDecay;
}
struct Emission {
uint256 xAllocations;
uint256 vote2Earn;
uint256 treasury;
}
Storage structure for the Emissions contract
Struct to store the state of emissions
struct EmissionsStorage {
contract IB3TR b3tr;
contract IXAllocationVotingGovernor xAllocationsGovernor;
address _xAllocations;
address _vote2Earn;
address _treasury;
address _migration;
uint256 _migrationAmount;
uint256 nextCycle;
uint256 cycleDuration;
uint256 xAllocationsDecay;
uint256 vote2EarnDecay;
uint256 maxVote2EarnDecay;
uint256 xAllocationsDecayPeriod;
uint256 vote2EarnDecayPeriod;
uint256 initialXAppAllocation;
uint256 treasuryPercentage;
uint256 lastEmissionBlock;
mapping(uint256 => struct Emissions.Emission) emissions;
uint256 totalEmissions;
bool _isEmissionsNotAligned;
}
constructor() public
function initialize(struct Emissions.InitializationData data) external
Initializes the contract with specific operational parameters for emissions management
Sets up the initial configurations including token addresses, allocation destinations, cycle parameters, and decay mechanics
Name | Type | Description |
---|---|---|
data | struct Emissions.InitializationData | A struct containing all necessary initialization data: - minter: Address with the minter role who can initiate token distributions - admin: Address with administrative rights - upgrader: Address authorized to upgrade the contract - b3trAddress: Contract address of the B3TR token - destinations: Array of addresses for emissions allocations: [XAllocations, Vote2Earn, Treasury, Migration] - initialXAppAllocation: Initial amount of tokens allocated for XAllocations - cycleDuration: Duration of each emission cycle in blocks - decaySettings: Array with decay rates and periods [XAllocations Decay Rate, Vote2Earn Decay Rate, XAllocations Decay Period, Vote2Earn Decay Period] - treasuryPercentage: Percentage of total emissions allocated to the treasury - maxVote2EarnDecay: Maximum allowable decay rate for Vote2Earn allocations to ensure sustainability - migrationAmount: Amount of tokens seed the migration account with |
function initializeV2(bool _isEmissionsNotAligned) external
Reinitializes the contract with new parameters
Name | Type | Description |
---|---|---|
_isEmissionsNotAligned | bool | Flag to indicate if emissions are aligned with the Emissions schedule |
function _authorizeUpgrade(address newImplementation) internal
Authorized upgrading of the contract implementation
This function can only be called by addresses with the UPGRADER_ROLE
Name | Type | Description |
---|---|---|
newImplementation | address | Address of the new contract implementation |
function bootstrap() external
Handles the bootstrapping of the initial emission cycle.
This function can only be called by addresses with the MINTER_ROLE and only when the next cycle is 0.
function start() external
Starts the emission process after the initial bootstrap.
This function can only be called by addresses with the MINTER_ROLE and only when the next cycle is 1.
function distribute() public virtual
Distributes the tokens for the current cycle, calculates allocations based on decay rates.
function _calculateNextXAllocation() internal view virtual returns (uint256)
Calculates the token allocation for XAllocations for the upcoming cycle, taking into account decay rates
Calculates emissions based on the previous cycle’s emissions and applies decay if a new decay period has started If it’s the first cycle, returns the initial allocation
Name | Type | Description |
---|---|---|
[0] | uint256 | uint256 The calculated number of tokens for the next cycle |
function _calculateVote2EarnDecayPeriods() internal view virtual returns (uint256)
Calculates the number of decay periods that have passed since the start of the emissions
Used to determine how many times the decay rate should be applied
to the Vote2Earn emissions The number of decay periods is calculated as
follows:
number of decay periods = floor(number of periods / decay period)
Name | Type | Description |
---|---|---|
[0] | uint256 | uint256 The number of decay periods since the start of emissions |
function _calculateVote2EarnDecayPercentage() internal view virtual returns (uint256)
Calculates the decay percentage for Vote2Earn allocations for the next cycle
The decay percentage is determined by the elapsed decay periods
and the specified decay rate, capped at a maximum decay rate The decay
percentage is calculated as follows:
decay percentage = decay rate * number of decay periods
The
decay percentage is capped at a maximum value to ensure
sustainability
Name | Type | Description |
---|---|---|
[0] | uint256 | uint256 The calculated decay percentage for the next cycle |
function _calculateVote2EarnAmount() internal view virtual returns (uint256)
Calculates the token allocation for Vote2Earn for the upcoming cycle
Applies the calculated decay percentage to the XAllocation from the upcoming cycle to determine Vote2Earn allocation
Name | Type | Description |
---|---|---|
[0] | uint256 | uint256 The calculated number of tokens for Vote2Earn for the next cycle |
function _calculateTreasuryAmount() internal view virtual returns (uint256)
Calculates the token allocation for the Treasury based on the total allocations to XAllocations and Vote2Earn
Treasury gets a percentage of the combined XAllocations and Vote2Earn amounts, adjusted by the treasury percentage
Name | Type | Description |
---|---|---|
[0] | uint256 | unit256 The calculated number of tokens for the Treasury for the next cycle |
function getXAllocationAmount(uint256 cycle) public view virtual returns (uint256)
Retrieves the XAllocation amount for a specified cycle
Returns the allocated amount if the cycle has been distributed, otherwise calculates the expected allocation
Name | Type | Description |
---|---|---|
cycle | uint256 | The cycle number to query |
Name | Type | Description |
---|---|---|
[0] | uint256 | uint256 The amount of XAllocations for the specified cycle |
function getVote2EarnAmount(uint256 cycle) public view virtual returns (uint256)
Retrieves the Vote2Earn allocation for a specified cycle
Returns the allocated amount if the cycle has been distributed, otherwise calculates the expected allocation
Name | Type | Description |
---|---|---|
cycle | uint256 | The cycle number to query |
Name | Type | Description |
---|---|---|
[0] | uint256 | uint256 The amount of Vote2Earn for the specified cycle |
function getTreasuryAmount(uint256 cycle) public view virtual returns (uint256)
Retrieves the Treasury allocation for a specified cycle
Returns the allocated amount if the cycle has been distributed, otherwise calculates the expected allocation
Name | Type | Description |
---|---|---|
cycle | uint256 | The cycle number to query |
Name | Type | Description |
---|---|---|
[0] | uint256 | uint256 The amount of Treasury allocation for the specified cycle |
function isCycleDistributed(uint256 cycle) public view virtual returns (bool)
Checks if a specific cycle’s allocations have been distributed
Name | Type | Description |
---|---|---|
cycle | uint256 | The cycle number to check |
Name | Type | Description |
---|---|---|
[0] | bool | True if the cycle has been distributed, false otherwise |
function isCycleEnded(uint256 cycle) public view virtual returns (bool)
Determines if a specific cycle has ended
Name | Type | Description |
---|---|---|
cycle | uint256 | The cycle number to check |
Name | Type | Description |
---|---|---|
[0] | bool | True if the cycle has ended, false otherwise |
function getCurrentCycle() public view virtual returns (uint256)
Retrieves the current cycle number
The current cycle is the next cycle minus one
Name | Type | Description |
---|---|---|
[0] | uint256 | uint256 The current cycle number |
function getNextCycleBlock() public view virtual returns (uint256)
Retrieves the block number when the next cycle will start
Name | Type | Description |
---|---|---|
[0] | uint256 | uint256 The starting block number of the next cycle |
function isNextCycleDistributable() public view virtual returns (bool)
Checks if the next cycle can start based on the block number
Name | Type | Description |
---|---|---|
[0] | bool | True if the next cycle can be started, false otherwise |
function getRemainingEmissions() public view returns (uint256)
Calculates the remaining emissions available for distribution
Name | Type | Description |
---|---|---|
[0] | uint256 | uint256 The total number of tokens still available for emission |
function treasury() public view returns (address)
Returns the address of the Treasury
function vote2Earn() public view returns (address)
Returns the address of the Vote2Earn allocation
function xAllocations() public view returns (address)
Returns the address for XAllocations
function b3tr() public view returns (contract IB3TR)
Returns the B3TR contract
function xAllocationsGovernor() public view returns (contract IXAllocationVotingGovernor)
Returns the XAllocations Governance contract
function cycleDuration() public view returns (uint256)
Retrieves the cycle duration in blocks
function nextCycle() public view returns (uint256)
Retrieves the block number of the next emission cycle
Name | Type | Description |
---|---|---|
[0] | uint256 | uint256 The block number of the next cycle |
function xAllocationsDecay() public view returns (uint256)
Retrieves the current decay rate for XAllocations
Name | Type | Description |
---|---|---|
[0] | uint256 | uint256 The decay rate as a percentage |
function vote2EarnDecay() public view returns (uint256)
Retrieves the current decay rate for Vote2Earn allocations
Name | Type | Description |
---|---|---|
[0] | uint256 | uint256 The decay rate as a percentage |
function maxVote2EarnDecay() public view returns (uint256)
Retrieves the maximum allowed decay rate for Vote2Earn
Name | Type | Description |
---|---|---|
[0] | uint256 | uint256 The maximum decay rate as a percentage |
function xAllocationsDecayPeriod() public view returns (uint256)
Retrieves the decay period for XAllocations
Name | Type | Description |
---|---|---|
[0] | uint256 | uint256 The number of blocks between decay periods |
function vote2EarnDecayPeriod() public view returns (uint256)
Retrieves the decay period for Vote2Earn allocations
Name | Type | Description |
---|---|---|
[0] | uint256 | uint256 The number of cycles between decay applications |
function initialXAppAllocation() public view returns (uint256)
Retrieves the initial allocation for XAllocations at the start of the first cycle
Name | Type | Description |
---|---|---|
[0] | uint256 | uint256 The amount of tokens initially allocated |
function treasuryPercentage() public view returns (uint256)
Retrieves the percentage of total emissions allocated to the Treasury
Name | Type | Description |
---|---|---|
[0] | uint256 | uint256 The treasury percentage |
function lastEmissionBlock() public view returns (uint256)
Retrieves the block number when the last emission occurred
Name | Type | Description |
---|---|---|
[0] | uint256 | uint256 The block number of the last emission |
function totalEmissions() public view returns (uint256)
Retrieves the total amount of emissions that have been distributed across all cycles
Name | Type | Description |
---|---|---|
[0] | uint256 | uint256 The total emissions distributed |
function emissions(uint256 cycle) public view returns (struct Emissions.Emission)
Retrieves the emission details for a specific cycle
Name | Type | Description |
---|---|---|
cycle | uint256 | The cycle number to query |
Name | Type | Description |
---|---|---|
[0] | struct Emissions.Emission | Emission A struct containing the allocations for XAllocations, Vote2Earn, and Treasury |
function isEmissionsNotAligned() public view returns (bool)
function version() public pure virtual returns (string)
Retrieves the current version of the contract
This function is used to identify the version of the contract and should be overridden in each new version
Name | Type | Description |
---|---|---|
[0] | string | The version of the contract |
function setXallocationsAddress(address xAllocationAddress) public virtual
Sets the address for XAllocations
Requires admin privileges and a non-zero address
Name | Type | Description |
---|---|---|
xAllocationAddress | address | The new address to set for XAllocations |
function setVote2EarnAddress(address vote2EarnAddress) public virtual
Sets the address for Vote2Earn allocations
Requires admin privileges and a non-zero address
Name | Type | Description |
---|---|---|
vote2EarnAddress | address | The new address to set for Vote2Earn |
function setTreasuryAddress(address treasuryAddress) public virtual
Sets the address for the Treasury
Requires admin privileges and a non-zero address
Name | Type | Description |
---|---|---|
treasuryAddress | address | The new address to set for the Treasury |
function setCycleDuration(uint256 _cycleDuration) public virtual
Sets the duration of each emission cycle
Requires admin privileges and a duration greater than 0
Name | Type | Description |
---|---|---|
_cycleDuration | uint256 | The duration of the cycle in blocks |
function setXAllocationsDecay(uint256 _decay) public virtual
Sets the decay rate for XAllocations
Requires admin privileges
Name | Type | Description |
---|---|---|
_decay | uint256 | Decay rate as a percentage |
function setVote2EarnDecay(uint256 _decay) public virtual
Sets the decay rate for Vote2Earn allocations
Requires admin privileges
Name | Type | Description |
---|---|---|
_decay | uint256 | Decay rate as a percentage |
function setXAllocationsDecayPeriod(uint256 _period) public virtual
Sets the number of cycles after which the XAllocations decay rate is applied
Requires admin privileges and a period greater than 0
Name | Type | Description |
---|---|---|
_period | uint256 | Number of cycles |
function setVote2EarnDecayPeriod(uint256 _period) public virtual
Sets the number of cycles after which the Vote2Earn decay rate is applied
Requires admin privileges and a period greater than 0
Name | Type | Description |
---|---|---|
_period | uint256 | Number of cycles |
function setTreasuryPercentage(uint256 _percentage) public virtual
Sets the treasury percentage allocation
The treasury percentage is a value between 0 and 10000, scaled by 100 to allow fractional percentages (87.5% for example) Requires admin privileges
Name | Type | Description |
---|---|---|
_percentage | uint256 | Treasury percentage (scaled by 100) |
function setMaxVote2EarnDecay(uint256 _maxVote2EarnDecay) public virtual
Sets the maximum decay rate for Vote2Earn allocations
Requires admin privileges and a decay rate between 0 and 100
Name | Type | Description |
---|---|---|
_maxVote2EarnDecay | uint256 | Maximum decay rate as a percentage |
function setXAllocationsGovernorAddress(address _xAllocationsGovernor) public
Sets the address for the XAllocations Governor
Requires that the voting period of the governor is less than the cycle duration Requires admin privileges and a non-zero address
Name | Type | Description |
---|---|---|
_xAllocationsGovernor | address | The new XAllocations Governor address |