RewardsLib

Git Source

State Variables

UNIT_DENOMINATOR

Unit denominotor for calculating all fees and rates in the system

All fees and rates are calculated out of 1e6

uint256 internal constant UNIT_DENOMINATOR = 1e6;

Functions

harvestOperatorRewards

Harvest rewards given to our operators for setting their cuttingboard weights ref - https://github.com/infrared-dao/infrared-contracts/blob/develop/src/staking/InfraredBERAFeeReceivor.sol#L83

function harvestOperatorRewards(
    RewardsStorage storage $,
    address ibera,
    address voter,
    address distributor
) external returns (uint256 _amt);

Parameters

NameTypeDescription
$RewardsStorageThe storage pointer for all rewards accumulators
iberaaddressThe address of the InfraredBERA token
voteraddressThe address of the voter (address(0) if IR token is not live)
distributoraddressThe address of the distributor

Returns

NameTypeDescription
_amtuint256The amount of rewards harvested

chargedFeesOnRewards

The amount of rewards going to the protocol treasury

Generic function to calculate the fees charged on rewards, returning the amount owed to the recipient, protocol, and voter.

the recepient is the amount of rewards being sent forward into the protocol for example a vault

function chargedFeesOnRewards(
    uint256 amount,
    uint256 totalFeeRate,
    uint256 protocolFeeRate
)
    public
    pure
    returns (uint256 recepient, uint256 voterFees, uint256 protocolFees);

Parameters

NameTypeDescription
amountuint256The amount of rewards to calculate fees on
totalFeeRateuint256The total fee rate to charge on rewards (protocol + voter)
protocolFeeRateuint256The rate to charge for protocol fees

Returns

NameTypeDescription
recepientuint256The amount of rewards to send to the recipient
voterFeesuint256The amount of rewards to send to the voter
protocolFeesuint256The amount of rewards to send to the protocol

_distributeFeesOnRewards

Distributes fees on rewards to the protocol, voter, and recipient.

_protocolFeeAmounts The accumulator for protocol fees per token

_voter The address of the voter

_token The address of the reward token

_amtVoter The amount of rewards for the voter

_amtProtocol The amount of rewards for the protocol

function _distributeFeesOnRewards(
    mapping(address => uint256) storage protocolFeeAmounts,
    address _voter,
    address _token,
    uint256 _amtVoter,
    uint256 _amtProtocol
) internal;

_handleTokenRewardsForVault

Handles non-InfraredBGT token rewards to the vault.

function _handleTokenRewardsForVault(
    RewardsStorage storage $,
    IInfraredVault _vault,
    address _token,
    address voter,
    uint256 _amount,
    uint256 _feeTotal,
    uint256 _feeProtocol,
    uint256 rewardsDuration
) internal;

Parameters

NameTypeDescription
$RewardsStorageRewardsStorage The storage pointer for all rewards accumulators.
_vaultIInfraredVaultIInfraredVault The address of the vault.
_tokenaddressaddress The reward token.
voteraddressaddress The address of the voter.
_amountuint256uint256 The amount of reward token to send to vault.
_feeTotaluint256uint256 The rate to charge for total fees on _amount.
_feeProtocoluint256uint256 The rate to charge for protocol treasury on total fees.
rewardsDurationuint256uint256 The duration of the rewards.

updateIRMintRate

Update the IR minting rate for the protocol.

This rate determines how many IR tokens are minted whenever BGT rewards are harvested.

For example, if the rate is 500,000 (0.5 * UNIT_DENOMINATOR), 0.5 IR is minted per BGT.

If the rate is 2,000,000 (2 * UNIT_DENOMINATOR), 2 IR are minted per BGT.

The actuall calculation is done in the harvestVault function when BGT rewards are harvested and IR tokens are minted accordingly.

function updateIRMintRate(RewardsStorage storage $, uint256 newRate) external;

Parameters

NameTypeDescription
$RewardsStorageThe storage pointer for all rewards accumulators
newRateuint256The new IR minting rate out of UNIT_DENOMINATOR(1e6 being 100% or a 1:1 rate)

delegateBGT

Delegates Berachain Governance Voting Power to a delegatee

function delegateBGT(address _delegatee, address bgt) external;

Parameters

NameTypeDescription
_delegateeaddressThe address to delegate voting power to
bgtaddressThe address of the BGT token

updateInfraredBERABribeSplit

Update the split ratio for iBERA and iBGT rewards

function updateInfraredBERABribeSplit(RewardsStorage storage $, uint256 _split)
    external;

Parameters

NameTypeDescription
$RewardsStorageThe storage pointer for all rewards accumulators
_splituint256The ratio for splitting received bribes to be iBERA and iBGT, weighted towards iBERA

updateFee

Update the fee rate for a given fee type

function updateFee(
    RewardsStorage storage $,
    ConfigTypes.FeeType _t,
    uint256 _fee
) external;

Parameters

NameTypeDescription
$RewardsStorageThe storage pointer for all rewards accumulators
_tConfigTypes.FeeTypeThe fee type to update
_feeuint256The new fee rate

claimProtocolFees

Claim protocol fees for a given token

function claimProtocolFees(
    RewardsStorage storage $,
    address _to,
    address _token
) external returns (uint256 _amountClaimed);

Parameters

NameTypeDescription
$RewardsStorageThe storage pointer for all rewards accumulators
_toaddressThe address to send the protocol fees to
_tokenaddressThe token to claim protocol fees for

harvestBase

Harvet's base rewards from the BGT contract, ie rewards from Distributor, given in BGT ref - https://github.com/berachain/contracts-monorepo/blob/main/src/pol/rewards/Distributor.sol#L160

The BGT accumilates in the contract, therfore can check balance(this) since all other BGT rewards are claimed and harvested atomically

Reward paid out to validators proposing a block, MUST be forwarded to IBERA.receivor, the fees are handled there. TODO: Link here.

function harvestBase(address ibgt, address bgt, address ibera)
    external
    returns (uint256 bgtAmt);

Parameters

NameTypeDescription
ibgtaddressThe address of the InfraredBGT toke
bgtaddressThe address of the BGT token
iberaaddressThe address of the InfraredBERA token

Returns

NameTypeDescription
bgtAmtuint256The amount of BGT rewards harvested

harvestVault

Harvests the accrued BGT rewards to a vault.

BGT transferred here directly to the user https://github.com/berachain/contracts-monorepo/blob/c374de32077ede0147985cf2bf6ed89570244a7e/src/pol/rewards/RewardVault.sol#L404

function harvestVault(
    RewardsStorage storage $,
    IInfraredVault vault,
    address bgt,
    address ibgt,
    address voter,
    address ir,
    uint256 rewardsDuration
) external returns (uint256 bgtAmt);

Parameters

NameTypeDescription
$RewardsStorage
vaultIInfraredVaultThe address of the InfraredRewardVault, wrapping an underlying RewardVault
bgtaddressThe address of the BGT token
ibgtaddressThe address of the InfraredBGT token
voteraddressThe address of the voter (0 until IR token is live)
iraddressThe address of the Infrared token
rewardsDurationuint256The duration of the rewards

Returns

NameTypeDescription
bgtAmtuint256The amount of BGT rewards harvested

harvestOldVault

Harvests the accrued BGT rewards to a vault.

BGT transferred here directly to the user https://github.com/berachain/contracts-monorepo/blob/c374de32077ede0147985cf2bf6ed89570244a7e/src/pol/rewards/RewardVault.sol#L404

function harvestOldVault(
    RewardsStorage storage $,
    IInfraredVault vault,
    IInfraredVault newVault,
    address bgt,
    address ibgt,
    address voter
) external returns (uint256 bgtAmt);

Parameters

NameTypeDescription
$RewardsStorage
vaultIInfraredVaultThe address of the InfraredRewardVault, wrapping an underlying RewardVault
newVaultIInfraredVault
bgtaddressThe address of the BGT token
ibgtaddressThe address of the InfraredBGT token
voteraddressThe address of the voter (0 until IR token is live)

Returns

NameTypeDescription
bgtAmtuint256The amount of BGT rewards harvested

harvestBribes

Harvest Bribes in tokens from RewardVault, sent to us via processIncentive ref - https://github.com/berachain/contracts-monorepo/blob/c374de32077ede0147985cf2bf6ed89570244a7e/src/pol/rewards/RewardVault.sol#L421

function harvestBribes(
    RewardsStorage storage $,
    address collector,
    address[] memory _tokens,
    bool[] memory whitelisted
) external returns (address[] memory tokens, uint256[] memory amounts);

Parameters

NameTypeDescription
$RewardsStorageThe storage pointer for all rewards accumulators
collectoraddressThe address of the bribe collector, which will auction off fees for WBERA
_tokensaddress[]The array of token addresses to harvest
whitelistedbool[]The array of booleans indicating if the token is whitelisted, and should be collected

harvestBoostRewards

Harvest boost rewards from the BGT staker (in HONEY -- likely)

function harvestBoostRewards(
    RewardsStorage storage $,
    address bgt,
    address ibgtVault,
    address voter,
    uint256 rewardsDuration
) external returns (address _token, uint256 _amount);

Parameters

NameTypeDescription
$RewardsStorageThe storage pointer for all rewards accumulators
bgtaddressThe address of the BGT token
ibgtVaultaddressThe address of the InfraredBGT vault
voteraddressThe address of the voter (address(0) if IR token is not live)
rewardsDurationuint256The duration of the rewards

Returns

NameTypeDescription
_tokenaddressThe rewards token harvested (likely hunny)
_amountuint256The amount of rewards harvested

collectBribesInWBERA

Callback from the BribeCollector to payout the WBERA bribes were auctioned off for ref - https://github.com/infrared-dao/infrared-contracts/blob/develop/src/core/BribeCollector.sol#L87

WBERA is split between the iBERA product (where it is redeemed for BERA) and the rest is sent to the IBGT vault.

function collectBribesInWBERA(
    RewardsStorage storage $,
    uint256 _amount,
    address wbera,
    address ibera,
    address ibgtVault,
    address voter,
    uint256 rewardsDuration
) external returns (uint256 amtInfraredBERA, uint256 amtIbgtVault);

Parameters

NameTypeDescription
$RewardsStorageStorage pointer for reward accumulators
_amountuint256The amount of WBERA our bribes were auctioned off for
wberaaddressThe address of the WBERA token
iberaaddressThe address of the InfraredBERA token
ibgtVaultaddressThe address of the InfraredBGT vault
voteraddressThe address of the voter (address(0) if IR token is not live)
rewardsDurationuint256The duration of the rewards

Returns

NameTypeDescription
amtInfraredBERAuint256The amount of WBERA sent to the iBERA product
amtIbgtVaultuint256The amount of WBERA sent to the IBGT vault

Events

ErrorMisconfiguredIRMinting

Emitted when protocol wants to mint IR but fails.

event ErrorMisconfiguredIRMinting(uint256 amount);

Parameters

NameTypeDescription
amountuint256uint256 The amount of IR that failed to mint

Structs

RewardsStorage

struct RewardsStorage {
    mapping(address => uint256) protocolFeeAmounts;
    uint256 irMintRate;
    uint256 bribeSplitRatio;
    mapping(uint256 => uint256) fees;
}