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
Name | Type | Description |
---|---|---|
_delegate | address | The 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
Name | Type | Description |
---|---|---|
_queueDelay | uint96 | The 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
Name | Type | Description |
---|---|---|
_minimumRedeemAmount | uint128 | The 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
Name | Type | Description |
---|---|---|
_processingFee | uint256 | The 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
Name | Type | Description |
---|---|---|
_open | bool | True 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
Name | Type | Description |
---|---|---|
rewardVault | address | The rewards vault to set the manager for. |
manager | address | The 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
Name | Type | Description |
---|---|---|
rewardVaults | address[] | The reward vaults to set the manager for. |
managers | address[] | Addresses of the managers. |
mint
Mints LBGT for a user.
function mint(
address user,
address rewardVault,
address recipient
)
external
nonReentrant
whenNotPaused
returns (uint256);
Parameters
Name | Type | Description |
---|---|---|
user | address | The user for whom rewards are claimed. |
rewardVault | address | The rewards vault from which rewards are claimed. |
recipient | address | The address receiving the minted LBGT. |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | The 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
Name | Type | Description |
---|---|---|
user | address | The user for whom rewards are claimed. |
rewardVault | address | The rewards vault from which rewards are claimed. |
recipient | address | The address receiving the minted LBGT. |
data | bytes32 |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | The 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
Name | Type | Description |
---|---|---|
users | address[] | Array of user addresses. |
rewardVaults | address[] | Array of rewards vault addresses corresponding to users. |
recipients | address[] | Array of recipient addresses. |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | The total amount of LBGT minted. |
queueRedeem
Queues a redeem request for a user.
function queueRedeem(uint128 amount) external whenNotPaused;
Parameters
Name | Type | Description |
---|---|---|
amount | uint128 | The amount of LBGT to redeem. |
redeem
Redeems LBGT for a user.
function redeem(uint128 amount, address recipient) external whenNotPaused;
Parameters
Name | Type | Description |
---|---|---|
amount | uint128 | The amount of LBGT to redeem. |
recipient | address | The address receiving the redeemed amount. |
processRedemptions
Processes redemption requests.
function processRedemptions(uint128 maxBatchSize, address recipient) external payable whenNotPaused;
Parameters
Name | Type | Description |
---|---|---|
maxBatchSize | uint128 | The maximum number of redemption requests to process. |
recipient | address | The 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
Name | Type | Description |
---|---|---|
pubkey | bytes | The pubkey of the validator to be boosted. |
amount | uint128 | The 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
Name | Type | Description |
---|---|---|
pubkey | bytes | The pubkey of the validator to cancel boost for. |
amount | uint128 | The 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
Name | Type | Description |
---|---|---|
pubkey | bytes | The pubkey of the validator to be boosted. |
Returns
Name | Type | Description |
---|---|---|
<none> | bool | bool 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
Name | Type | Description |
---|---|---|
pubkey | bytes | The pubkey of the validator to remove boost from. |
amount | uint128 | The 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
Name | Type | Description |
---|---|---|
pubkey | bytes | The pubkey of the validator to cancel drop boost for. |
amount | uint128 | The 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
Name | Type | Description |
---|---|---|
pubkey | bytes | The pubkey of the validator to remove boost from. |
Returns
Name | Type | Description |
---|---|---|
<none> | bool | bool 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
Name | Type | Description |
---|---|---|
<none> | address | The 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
Name | Type | Description |
---|---|---|
rewardVault | address | The rewards vault to get the BGT operator from. |
account | address | The user account to get the BGT operator from. |
Returns
Name | Type | Description |
---|---|---|
<none> | address | The 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
Name | Type | Description |
---|---|---|
<none> | uint256 | The amount of boostable BGT. |
receive
receive() external payable;
fallback
fallback() external payable;