RewardsLib
Constants
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
_wberaAndIbera
External library calls run via DELEGATECALL, so address(this)
inside this library is the calling Infrared contract. We can
therefore read its public wbera() / ibera() getters back
out without expanding the legacy selectors with new parameters
— preserving the live V1_10 ABI while adding vnext semantics.
function _wberaAndIbera()
internal
view
returns (address wbera, address ibera);
_sweepWberaToReceivor
Sweep WBERA accrued on Infrared (base + commission from the vnext
BlockRewardController) to iBERA’s receivor. Subtracts the
protocolFeeAmounts[wbera] accumulator so we never sweep WBERA
that bribes have already earmarked as protocol revenue. Read
via the public getter so we don’t have to thread storage $
through legacy selectors.
function _sweepWberaToReceivor(address ibera) internal returns (uint256);
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 distributor
) external returns (uint256 amountOperators);
Parameters
| Name | Type | Description |
|---|---|---|
$ | RewardsStorage | The storage pointer for all rewards accumulators |
ibera | address | The address of the InfraredBERA token |
distributor | address | The address of the distributor |
Returns
| Name | Type | Description |
|---|---|---|
amountOperators | uint256 | The amount of rewards harvested |
chargedFeesOnRewards
Generic function to calculate the fees charged on rewards, returning the amount owed to the recipient and protocol.
the recipient is the amount of rewards being sent forward into the protocol for example a vault
function chargedFeesOnRewards(uint256 amount, uint256 totalFeeRate)
public
pure
returns (uint256 recipient, uint256 protocolFees);
Parameters
| Name | Type | Description |
|---|---|---|
amount | uint256 | The amount of rewards to calculate fees on |
totalFeeRate | uint256 | The total fee rate to charge on rewards (protocol + voter) |
Returns
| Name | Type | Description |
|---|---|---|
recipient | uint256 | The amount of rewards to send to the recipient |
protocolFees | uint256 | The 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
_token The address of the reward token
_amtProtocol The amount of rewards for the protocol
function _distributeFeesOnRewards(
mapping(address => uint256) storage protocolFeeAmounts,
address _token,
uint256 _amtProtocol
) internal;
_handleTokenRewardsForVault
Handles non-InfraredBGT token rewards to the vault.
function _handleTokenRewardsForVault(
RewardsStorage storage $,
IInfraredVault _vault,
address _token,
uint256 _amount,
uint256 _feeTotal,
uint256 rewardsDuration
) internal;
Parameters
| Name | Type | Description |
|---|---|---|
$ | RewardsStorage | RewardsStorage The storage pointer for all rewards accumulators. |
_vault | IInfraredVault | IInfraredVault The address of the vault. |
_token | address | address The reward token. |
_amount | uint256 | uint256 The amount of reward token to send to vault. |
_feeTotal | uint256 | uint256 The rate to charge for total fees on _amount. |
rewardsDuration | uint256 | uint256 The duration of the rewards. |
delegateBGT
Delegates Berachain Governance Voting Power to a delegatee
function delegateBGT(address _delegatee, address bgt) external;
Parameters
| Name | Type | Description |
|---|---|---|
_delegatee | address | The address to delegate voting power to |
bgt | address | The address of the BGT token |
updateInfraredBERABribeSplit
Update the split ratio for iBERA and iBGT rewards
function updateInfraredBERABribeSplit(
RewardsStorage storage $,
uint256 _split
) external;
Parameters
| Name | Type | Description |
|---|---|---|
$ | RewardsStorage | The storage pointer for all rewards accumulators |
_split | uint256 | The ratio for splitting received bribes to be iBERA and iBGT, weighted towards iBERA |
updateIRSplit
Update the split ratio for IR and iBGT rewards
function updateIRSplit(RewardsStorage storage $, uint256 _split) external;
Parameters
| Name | Type | Description |
|---|---|---|
$ | RewardsStorage | The storage pointer for all rewards accumulators |
_split | uint256 | The ratio for splitting iBGT Vault rewards to IR, weighted towards IR |
updateFee
Update the fee rate for a given fee type
function updateFee(
RewardsStorage storage $,
ConfigTypes.FeeType _t,
uint256 _fee
) external;
Parameters
| Name | Type | Description |
|---|---|---|
$ | RewardsStorage | The storage pointer for all rewards accumulators |
_t | ConfigTypes.FeeType | The fee type to update |
_fee | uint256 | The new fee rate |
claimProtocolFees
Claim protocol fees for a given token
function claimProtocolFees(
RewardsStorage storage $,
address _to,
address _token
) external returns (uint256 _amountClaimed);
Parameters
| Name | Type | Description |
|---|---|---|
$ | RewardsStorage | The storage pointer for all rewards accumulators |
_to | address | The address to send the protocol fees to |
_token | address | The 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.
Harvest base + commission rewards via the legacy BGT redeem
path and sweep accrued WBERA from the vnext emission stream
to iBERA’s receivor — both legs are now executed by every call
to this selector so the live InfraredV1_10 wrapper does not
need to change.
BGT leg: unchanged — redeems accrued BGT for BERA to the iBERA receivor (BERA-backing-aware via the existing try/catch).
WBERA leg: sweeps balanceOf(this) - protocolFeeAmounts[wbera],
unwraps, and forwards as native BERA to the iBERA receivor.
Subtracting the protocol-fee accumulator guarantees we never
sweep WBERA earmarked by the bribe pipeline. Keepers must run
harvestBribes → collector.claimFees → collectBribes
before this call so no bribe-WBERA lingers when the sweep fires.
Return value is bgtAmt + wberaAmt. Pre-fork only the BGT leg
contributes; post-fork only the WBERA leg does. The event slot
named _bgtAmt on IInfraredV1_10.BaseHarvested thus carries
BERA-equivalent units after the vnext flip.
function harvestBase(address ibgt, address bgt, address ibera)
external
returns (uint256 bgtAmt);
Parameters
| Name | Type | Description |
|---|---|---|
ibgt | address | The address of the InfraredBGT toke |
bgt | address | The address of the BGT token |
ibera | address | The address of the InfraredBERA token |
Returns
| Name | Type | Description |
|---|---|---|
bgtAmt | uint256 | The amount of BGT rewards harvested |
auctionBase
Alternative to Harvet base rewards, auctioning iBGT on harvestBaseCollector, from BGT rewards from Distributor 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
BGT leg unchanged. WBERA leg appended so the auction-mode path
sweeps base + commission WBERA to iBERA’s receivor on the same
call, matching harvestBase. Selector preserved.
function auctionBase(
address ibgt,
address bgt,
address harvestBaseCollector
) external returns (uint256 bgtAmt);
Parameters
| Name | Type | Description |
|---|---|---|
ibgt | address | The address of the InfraredBGT toke |
bgt | address | The address of the BGT token |
harvestBaseCollector | address | The address of the harvestBaseCollector contract |
Returns
| Name | Type | Description |
|---|---|---|
bgtAmt | uint256 | The amount of BGT rewards harvested |
harvestVault
Harvests the accrued vault rewards. Handles both the legacy BGT payout and the vnext WBERA payout in a single call: pre-migration only the BGT delta is non-zero, post-migration only the WBERA delta is, and during the per-vault lazy switch both can be.
vnext _safeTransferRewardToken (RewardVault.sol:600-604)
can deliver BGT and WBERA in the same getReward call.
Measuring both balance deltas catches every reward dollar
regardless of which side of the switch the vault is on.
Selector is preserved from the legacy V1_10 surface so the
live InfraredV1_10 caller does not need to change. The
wbera and ibera addresses are fetched from the calling
contract via IInfrared(address(this)), which works because
external library calls run via DELEGATECALL — address(this)
inside the library is the Infrared proxy.
The single returned bgtAmt is a BERA-equivalent total of
the BGT rewards harvested plus the iBERA shares minted
from the WBERA leg. The naming is preserved for ABI/event
compatibility; the unit can mean iBERA-shares post-migration.
function harvestVault(
RewardsStorage storage $,
IInfraredVault vault,
address bgt,
address ibgt
) external returns (uint256 bgtAmt);
Returns
| Name | Type | Description |
|---|---|---|
bgtAmt | uint256 | BGT + iBERA-shares total (see unit note above). |
_harvestRewardsVaultTo
Shared harvest body for harvestVault / harvestOldVault:
claims the underlying Berachain rewardsVault for from, measures
both BGT and WBERA balance deltas, and routes each non-zero leg
into to via _handleTokenRewardsForVault (which self-registers
the reward token on the destination vault when missing). The two
route helpers below keep the per-leg stack footprint small —
inlining both branches here trips solc’s stack-too-deep.
function _harvestRewardsVaultTo(
RewardsStorage storage $,
IInfraredVault from,
IInfraredVault to,
address bgt,
address ibgt
) internal returns (uint256 bgtAmt);
_routeBgtRewardsToVault
BGT branch: mint iBGT, then defer to _handleTokenRewardsForVault
so the destination vault self-registers iBGT if it isn’t already
a reward token there (a no-op for normal vaults — the InfraredVault
constructor pre-registers iBGT — but cheap insurance for migration
and transitional paths).
function _routeBgtRewardsToVault(
RewardsStorage storage $,
IInfraredVault vault,
address ibgt,
uint256 bgtAmt
) internal;
_routeWberaRewardsToVault
WBERA branch: unwrap, mint iBERA, then defer to
_handleTokenRewardsForVault. The self-registering addReward
inside the helper is what makes transitional / freshly-migrated
vaults (which have iBGT pre-registered but not iBERA) accept the
vnext WBERA-emission leg without an out-of-band governance call.
The notified reward token is raw iBERA.
function _routeWberaRewardsToVault(
RewardsStorage storage $,
IInfraredVault vault,
address wbera,
address ibera,
uint256 wberaAmt
) internal returns (uint256 iberaShares);
_wberaToIbera
Convert a WBERA reward amount into the reward token distributed to
stakers: unwrap WBERA to native BERA and mint iBERA, returning the
minted iBERA shares. Centralizes the conversion shared by the vault
and per-user harvest legs. The distributed reward token is raw
iBERA. iBERA is read from the calling Infrared contract
(DELEGATECALL — address(this) is the proxy), matching the
_wberaAndIbera() self-fetch convention.
function _wberaToIbera(address wbera, address ibera, uint256 wberaAmt)
internal
returns (uint256 iberaShares);
Returns
| Name | Type | Description |
|---|---|---|
iberaShares | uint256 | The amount of iBERA minted from wberaAmt. |
harvestVaultForUser
Harvests a Berachain reward vault as operator for user,
handling both BGT and WBERA payouts in a single call.
BGT branch: mints iBGT, takes fee, transfers post-fee iBGT to user.
WBERA branch: unwraps, mints iBERA, takes fee, transfers post-fee
iBERA to user. See harvestVault for transition semantics
and the rationale for keeping the legacy selector.
function harvestVaultForUser(
RewardsStorage storage $,
IBerachainRewardsVault vault,
address bgt,
address ibgt,
address user
) external returns (uint256 bgtAmt);
Returns
| Name | Type | Description |
|---|---|---|
bgtAmt | uint256 | BGT + iBERA-shares total in BERA-equivalent units. |
_payBgtToUser
Mint iBGT, charge fee, transfer post-fee iBGT to user.
function _payBgtToUser(
RewardsStorage storage $,
address ibgt,
address user,
uint256 bgtDelta
) internal;
_payWberaAsIberaToUser
Unwrap WBERA, mint iBERA, charge fee, transfer the post-fee iBERA to the user. Fee accrues in iBERA.
function _payWberaAsIberaToUser(
RewardsStorage storage $,
address wbera,
address ibera,
address user,
uint256 wberaDelta
) internal returns (uint256 iberaShares);
externalVaultRewards
View rewards claimable on a berachain reward vault for user.
RewardVault.earned(user) returns the active reward token’s
earned amount; we use rewardToken() (via a probe interface,
since neither upstream IRewardVault declares it) to
discriminate the BGT vs WBERA leg. Pre-fork returns the
post-fee iBGT amount; post-fork returns the post-fee iBERA
shares (the iBERA previewMint of the earned WBERA) — both
surfaced through the legacy iBgtAmount slot so the caller and
ABI stay unchanged.
function externalVaultRewards(
RewardsStorage storage $,
IBerachainRewardsVault vault,
address user
) external view returns (uint256 iBgtAmount);
harvestOldVault
Harvests an old vault, forwarding both BGT (legacy) and WBERA
(vnext) rewards into its successor newVault.
Same dual-delta semantics as harvestVault. Selector preserved.
function harvestOldVault(
RewardsStorage storage $,
IInfraredVault vault,
IInfraredVault newVault,
address bgt,
address ibgt
) external returns (uint256 bgtAmt);
Returns
| Name | Type | Description |
|---|---|---|
bgtAmt | uint256 | BGT + iBERA-shares total in BERA-equivalent units. |
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
WBERA is never collected as a bribe. Post-vnext it is the
base/commission token swept to the iBERA receivor by
harvestBase/_sweepWberaToReceivor, and it is the collector’s
own payout token — auctioning WBERA for WBERA is meaningless.
Because both the bribe sweep and the base sweep read the same
balanceOf(wbera) - protocolFeeAmounts[wbera] pool, collecting
WBERA here would divert accumulated base rewards into the bribe
split. We skip it on-chain so keeper input cannot misroute it.
function harvestBribes(
RewardsStorage storage $,
address collector,
address[] memory _tokens,
bool[] memory whitelisted
) external returns (address[] memory tokens, uint256[] memory amounts);
Parameters
| Name | Type | Description |
|---|---|---|
$ | RewardsStorage | The storage pointer for all rewards accumulators |
collector | address | The address of the bribe collector, which will auction off fees for WBERA |
_tokens | address[] | The array of token addresses to harvest |
whitelisted | bool[] | 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,
uint256 rewardsDuration
) external returns (address _token, uint256 _amount);
Parameters
| Name | Type | Description |
|---|---|---|
$ | RewardsStorage | The storage pointer for all rewards accumulators |
bgt | address | The address of the BGT token |
ibgtVault | address | The address of the InfraredBGT vault |
rewardsDuration | uint256 | The duration of the rewards |
Returns
| Name | Type | Description |
|---|---|---|
_token | address | The rewards token harvested (likely hunny) |
_amount | uint256 | The amount of rewards harvested |
redeemIbgtForBera
redeem ibgt for bera
function redeemIbgtForBera(address bgt, address ibgt, uint256 amount)
external;
Parameters
| Name | Type | Description |
|---|---|---|
bgt | address | The address of the BGT token |
ibgt | address | The address of the iBGT token |
amount | uint256 | Amount of ibgt to redeem |
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/depreciated/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 irCollector,
uint256 rewardsDuration
)
external
returns (
uint256 amtInfraredBERA,
uint256 amtIbgtVault,
uint256 amountIR
);
Parameters
| Name | Type | Description |
|---|---|---|
$ | RewardsStorage | Storage pointer for reward accumulators |
_amount | uint256 | The amount of WBERA our bribes were auctioned off for |
wbera | address | The address of the WBERA token |
ibera | address | The address of the InfraredBERA token |
ibgtVault | address | The address of the InfraredBGT vault |
irCollector | address | |
rewardsDuration | uint256 | The duration of the rewards |
Returns
| Name | Type | Description |
|---|---|---|
amtInfraredBERA | uint256 | The amount of WBERA sent to the iBERA product |
amtIbgtVault | uint256 | The amount of WBERA sent to the IBGT vault |
amountIR | uint256 |
collectBribesInIBGT
Callback from the BribeCollector to payout the iBGT bribes were auctioned off for ref - https://github.com/infrared-dao/infrared-contracts/blob/develop/src/depreciated/core/BribeCollector.sol#L87
iBGT is split between the iBERA product (where it is redeemed for BERA) and the rest is sent to the IBGT vault.
function collectBribesInIBGT(
RewardsStorage storage $,
uint256 _amount,
address ibgt,
address ibgtVault,
address irCollector,
address harvestBaseCollector,
uint256 rewardsDuration
)
external
returns (
uint256 amtInfraredBERA,
uint256 amtIbgtVault,
uint256 amountIR
);
Parameters
| Name | Type | Description |
|---|---|---|
$ | RewardsStorage | Storage pointer for reward accumulators |
_amount | uint256 | The amount of iBGT our bribes were auctioned off for |
ibgt | address | The address of the iBGT token |
ibgtVault | address | The address of the InfraredBGT vault |
irCollector | address | |
harvestBaseCollector | address | The address of base collector auction contract |
rewardsDuration | uint256 | The duration of the rewards |
Returns
| Name | Type | Description |
|---|---|---|
amtInfraredBERA | uint256 | The amount of iBGT sent to the iBERA product |
amtIbgtVault | uint256 | The amount of iBGT sent to the IBGT vault |
amountIR | uint256 |
collectBribesInIR
Callback from the BribeCollector to payout the IR bribes were auctioned off for ref - https://github.com/infrared-dao/infrared-contracts/blob/develop/src/core/BribeCollector.sol#L87
IR is split between the iBERA product (where it is redeemed for BERA) and the rest is sent to the IBGT vault and sIR.
function collectBribesInIR(
RewardsStorage storage $,
uint256 _amount,
address ir,
address ibgtVault,
address irCollector,
address harvestBaseCollector,
uint256 rewardsDuration
)
external
returns (
uint256 amtInfraredBERA,
uint256 amtIbgtVault,
uint256 amountIR
);
Parameters
| Name | Type | Description |
|---|---|---|
$ | RewardsStorage | Storage pointer for reward accumulators |
_amount | uint256 | The amount of IR our bribes were auctioned off for |
ir | address | The address of the IR token |
ibgtVault | address | The address of the InfraredBGT vault |
irCollector | address | |
harvestBaseCollector | address | The address of base collector auction contract |
rewardsDuration | uint256 | The duration of the rewards |
Returns
| Name | Type | Description |
|---|---|---|
amtInfraredBERA | uint256 | The amount of iBGT sent to the iBERA product |
amtIbgtVault | uint256 | The amount of iBGT sent to the IBGT vault |
amountIR | uint256 | The amount of IR sent to the sIR |
Structs
RewardsStorage
struct RewardsStorage {
mapping(address => uint256) protocolFeeAmounts;
uint256 irMintRate;
uint256 bribeSplitRatio;
mapping(uint256 => uint256) fees;
uint256 irSplitRatio;
}