ContractsBeraPaw Forge

BeraPawForge

Author: BeraPaw

Core contract for BeraPaw protocol that holds BGT and issues LBGT at 1:1 ratio. It is also has hooks for delegation operations and reward distribution.

*This contract:

  • Holds BGT tokens and issues LBGT at 1:1 ratio
  • Manages redemption queue for LBGT->BGT conversions
  • Handles reward collection and distribution
  • Controls BGT boosting operations
  • Collects BGT rewards from BGT staking contract*

State Variables

bgt

IBGT private constant bgt = IBGT(Constants.BGT);

lbgt

LBGT private constant lbgt = LBGT(Constants.LBGT);

bgtStaker

IBGTStaker private constant bgtStaker = IBGTStaker(Constants.BGT_STAKER);

honey

IERC20 private constant honey = IERC20(Constants.HONEY);

lbgtManager

Returns the manager address for a given account and rewards vault

Used to track who can manage LBGT rewards for an account

mapping(address account => mapping(address rewardVault => address manager)) public lbgtManager;

redeemPosition

Returns the redeem position for a given account

Contains details about user’s pending redemption

mapping(address account => RedeemPosition) public redeemPosition;

redeemQueue

Returns redeem queue entry at specified index

Used to track all redemption requests in order

RedeemQueue[] public redeemQueue;

redeemQueueIndex

Returns the current index in the redeem queue

Represents the next position to be processed

uint128 public redeemQueueIndex;

totalRedeemQueue

Returns total number of entries in redeem queue

Represents total redemption requests

uint128 public totalRedeemQueue;

processingFee

Returns current processing fee

Fee charged for processing redemptions

uint256 public processingFee;

queueDelay

Returns delay period for queue processing

Minimum time that must pass before processing redemptions

uint96 public queueDelay;

minimumRedeemAmount

Returns minimum amount required for redemption

Prevents dust amounts from being redeemed

uint128 public minimumRedeemAmount;

isProcessRedemptionsOpen

Returns whether redemption processing is currently enabled

Controls if redemptions can be processed

bool public isProcessRedemptionsOpen;

Functions

onlyUserOrManager

modifier onlyUserOrManager(address _user, address _rewardVault);

constructor

Note: oz-upgrades-unsafe-allow: constructor

constructor();

initialize

function initialize(address _owner) public initializer;

pause

Pause all user functions.

Only the curator can pause the forge.

function pause() public onlyRole(ROLE_CURATOR);

unpause

Unpause the forge.

Only the admin can unpause the forge.

function unpause() public onlyRole(ROLE_ADMIN);

delegate

Delegates the underlying BGT token to another address for voting purposes. this address can vote on behalf of this contract. Should be set to the governance timelock contract.

Only the admin can delegate the LBGT token.

function delegate(address _delegate) public onlyRole(ROLE_ADMIN);

Parameters

NameTypeDescription
_delegateaddressThe address to delegate the underlying BGT token to.

setQueueDelay

Sets the queue delay for redemptions.

Only the admin can set the queue delay.

function setQueueDelay(uint96 _queueDelay) public onlyRole(ROLE_ADMIN);

Parameters

NameTypeDescription
_queueDelayuint96The new queue delay in blocks.

setMinimumRedeemAmount

Sets the minimum redeem amount.

Only the admin can set the minimum redeem amount.

function setMinimumRedeemAmount(uint128 _minimumRedeemAmount) public onlyRole(ROLE_ADMIN);

Parameters

NameTypeDescription
_minimumRedeemAmountuint128The new minimum redeem amount.

setProcessingFee

Sets the processing fee for redemptions.

Only the admin can set the processing fee.

function setProcessingFee(uint256 _processingFee) public onlyRole(ROLE_ADMIN);

Parameters

NameTypeDescription
_processingFeeuint256The new processing fee as a percentage (1e18 = 100%).

setOpenProcessRedemptions

Sets whether redemption processing is open to non-processors

Only callable by GOD role

function setOpenProcessRedemptions(bool _open) public onlyRole(ROLE_GOD);

Parameters

NameTypeDescription
_openboolTrue to allow anyone to process redemptions, false to restrict to processors only

recover

function recover(address token, address to, uint256 amount) external onlyRole(ROLE_GOD);

setManager

Recovers ERC20 tokens accidentally sent to the contract

Only callable by GOD role

function setManager(address rewardVault, address manager) external;

Parameters

NameTypeDescription
rewardVaultaddressThe rewards vault to set the manager for.
manageraddressThe address of the manager.

setManagerMulti

Sets the managers for a set of reward vaults.

rewardVaults and managers must have the same length.

function setManagerMulti(address[] calldata rewardVaults, address[] calldata managers) external;

Parameters

NameTypeDescription
rewardVaultsaddress[]The reward vaults to set the manager for.
managersaddress[]Addresses of the managers.

mint

Mints LBGT for a user.

function mint(
    address user,
    address rewardVault,
    address recipient
)
    external
    nonReentrant
    whenNotPaused
    returns (uint256);

Parameters

NameTypeDescription
useraddressThe user for whom rewards are claimed.
rewardVaultaddressThe rewards vault from which rewards are claimed.
recipientaddressThe address receiving the minted LBGT.

Returns

NameTypeDescription
<none>uint256The amount of LBGT minted.

mintReferred

Mints LBGT for a user with a referrer.

function mintReferred(
    address user,
    address rewardVault,
    address recipient,
    bytes32 data
)
    external
    nonReentrant
    whenNotPaused
    returns (uint256);

Parameters

NameTypeDescription
useraddressThe user for whom rewards are claimed.
rewardVaultaddressThe rewards vault from which rewards are claimed.
recipientaddressThe address receiving the minted LBGT.
databytes32

Returns

NameTypeDescription
<none>uint256The amount of LBGT minted.

mintMulti

Mints LBGT for multiple users.

function mintMulti(
    address[] calldata users,
    address[] calldata rewardVaults,
    address[] calldata recipients
)
    external
    nonReentrant
    whenNotPaused
    returns (uint256);

Parameters

NameTypeDescription
usersaddress[]Array of user addresses.
rewardVaultsaddress[]Array of rewards vault addresses corresponding to users.
recipientsaddress[]Array of recipient addresses.

Returns

NameTypeDescription
<none>uint256The total amount of LBGT minted.

queueRedeem

Queues a redeem request for a user.

function queueRedeem(uint128 amount) external whenNotPaused;

Parameters

NameTypeDescription
amountuint128The amount of LBGT to redeem.

redeem

Redeems LBGT for a user.

function redeem(uint128 amount, address recipient) external whenNotPaused;

Parameters

NameTypeDescription
amountuint128The amount of LBGT to redeem.
recipientaddressThe address receiving the redeemed amount.

processRedemptions

Processes redemption requests.

function processRedemptions(uint128 maxBatchSize, address recipient) external payable whenNotPaused;

Parameters

NameTypeDescription
maxBatchSizeuint128The maximum number of redemption requests to process.
recipientaddressThe address receiving the redeemed amount.

collectStakerReward

function collectStakerReward(address to) external onlyRole(ROLE_REWARD_COLLECTOR) returns (uint256);

queueBoost

Queues a new boost of the validator with an amount of BGT from msg.sender.

Reverts if msg.sender does not have enough unboosted balance to cover amount.

function queueBoost(bytes calldata pubkey, uint128 amount) external onlyRole(ROLE_BOOSTER);

Parameters

NameTypeDescription
pubkeybytesThe pubkey of the validator to be boosted.
amountuint128The amount of BGT to use for the queued boost.

cancelBoost

Cancels a queued boost of the validator removing an amount of BGT for msg.sender.

Reverts if msg.sender does not have enough queued balance to cover amount.

function cancelBoost(bytes calldata pubkey, uint128 amount) external onlyRole(ROLE_BOOSTER);

Parameters

NameTypeDescription
pubkeybytesThe pubkey of the validator to cancel boost for.
amountuint128The amount of BGT to remove from the queued boost.

activateBoost

Boost the validator with an amount of BGT.

function activateBoost(bytes calldata pubkey) external onlyRole(ROLE_BOOSTER) returns (bool);

Parameters

NameTypeDescription
pubkeybytesThe pubkey of the validator to be boosted.

Returns

NameTypeDescription
<none>boolbool False if amount is zero or if enough time has not passed, otherwise true.

queueDropBoost

Queues a drop boost of the validator removing an amount of BGT for sender.

Reverts if does not have enough boosted balance to cover amount.

function queueDropBoost(bytes calldata pubkey, uint128 amount) external onlyRole(ROLE_BOOSTER);

Parameters

NameTypeDescription
pubkeybytesThe pubkey of the validator to remove boost from.
amountuint128The amount of BGT to remove from the boost.

cancelDropBoost

Cancels a queued drop boost of the validator removing an amount of BGT for sender.

function cancelDropBoost(bytes calldata pubkey, uint128 amount) external onlyRole(ROLE_BOOSTER);

Parameters

NameTypeDescription
pubkeybytesThe pubkey of the validator to cancel drop boost for.
amountuint128The amount of BGT to remove from the queued drop boost.

dropBoost

Drops an amount of BGT from an existing boost of validator.

function dropBoost(bytes calldata pubkey) external onlyRole(ROLE_BOOSTER) returns (bool);

Parameters

NameTypeDescription
pubkeybytesThe pubkey of the validator to remove boost from.

Returns

NameTypeDescription
<none>boolbool False if amount is zero or if enough time has not passed, otherwise true.

lbgtAddress

Returns the LBGT token address.

function lbgtAddress() public pure returns (address);

Returns

NameTypeDescription
<none>addressThe address of LBGT.

getBGTOperator

Returns the BGT operator address for the given rewards vault and user.

The BGT operator is the address that can claim BGT rewards for the given user and rewards vault.

function getBGTOperator(address rewardVault, address account) public view returns (address);

Parameters

NameTypeDescription
rewardVaultaddressThe rewards vault to get the BGT operator from.
accountaddressThe user account to get the BGT operator from.

Returns

NameTypeDescription
<none>addressThe BGT operator address for the given rewards vault and user.

boostableBGT

Returns the amount of BGT minus the amount queued for redeem.

function boostableBGT() public view returns (uint256);

Returns

NameTypeDescription
<none>uint256The amount of boostable BGT.

receive

receive() external payable;

fallback

fallback() external payable;