iBGT staking pool

For protocols like stable coins, borrow/lend platforms, iBGT is a great way to earn yield on the platform’s native token. This guide will show you how to integrate the iBGT vault into your platform.

Steps

1. Install the required contracts

Terminal
forge install github.com/infrared-dao/infrared-contracts.git

2. Import the required contracts

import {InfraredVault} from "@core/InfraredVault.sol";
import {IERC20, SafeERC20} from "@core/MultiRewards.sol";
import {IInfraredVault} from "@interfaces/IInfraredVault.sol";

3. Set the relevant addresses in storage

/**
 * @notice Construct the ExampleVaultIntegration contract.
 * @param ibgtVault address The address of the iBGT vault.
 * @param ibgtToken address The address of the iBGT token.
 */
constructor(address ibgtVault, address ibgtToken) {
    _ibgtVault = InfraredVault(ibgtVault);
    _ibgtToken = IERC20(ibgtToken);
    _ibgtToken.approve(address(_ibgtVault), type(uint256).max);
}

4. Allow users to deposit iBGT tokens to the vault

/**
* @notice Deposit iBGT tokens to the vault.
* @param amount uint256 The amount of iBGT tokens to deposit.
*/
function deposit(uint256 amount) external {
    /// require that the user has approved the contract to spend their iBGT tokens.
    _ibgtToken.safeTransferFrom(msg.sender, address(this), amount);
 
    /// deposit the iBGT tokens to the vault.
    _ibgtVault.stake(amount);
 
    /// *** Additional logic can be added here *** ///
}

5. Claim rewards from the vault

/**
* @notice Claim rewards from the vault.
*/
function claimRewards() external {
    /// claim the rewards from the vault.
    _ibgtVault.getReward();
 
    /// *** Additional logic can be added here *** ///
}

6. Compound the iBGT and stake it back to the vault

/**
* @notice Harvest rewards from the vault.
*/
function compoundRewards() external {
    uint256 balance = _ibgtToken.balanceOf(address(this));
    if (balance > 0) {
        /// deposit the iBGT tokens to the vault.
        _ibgtVault.stake(balance);
    } else {
        revert("No rewards to compound");
    }
}

7. Claim the rest of the rewards (ie. HONEY, wBERA etc)

/**
* @notice Claim the rest of the rewards.
*/
function claimRewards() external {
    /// claim the rewards from the vault.
    _ibgtVault.getReward();
 
    /// *** Additional logic can be added here *** ///
}

Full example:

// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.22;
 
import {InfraredVault} from "@core/InfraredVault.sol";
import {IERC20, SafeERC20} from "@core/MultiRewards.sol";
import {IInfraredVault} from "@interfaces/IInfraredVault.sol";
 
contract ExampleVaultIntegration {
    using SafeERC20 for IERC20;
 
    /// @notice the iBGT vault.
    InfraredVault private immutable _ibgtVault;
 
    /// @notice iBGT token.
    IERC20 private immutable _ibgtToken;
 
    /**
     * @notice Construct the ExampleVaultIntegration contract.
     * @param ibgtVault address The address of the iBGT vault.
     * @param ibgtToken address The address of the iBGT token.
     */
    constructor(address ibgtVault, address ibgtToken) {
        _ibgtVault = InfraredVault(ibgtVault);
        _ibgtToken = IERC20(ibgtToken);
        _ibgtToken.approve(address(_ibgtVault), type(uint256).max);
    }
 
    /**
     * @notice Deposit iBGT tokens to the vault.
     * @param amount uint256 The amount of iBGT tokens to deposit.
     */
    function deposit(uint256 amount) external {
        /// require that the user has approved the contract to spend their iBGT tokens.
        _ibgtToken.safeTransferFrom(msg.sender, address(this), amount);
 
        /// deposit the iBGT tokens to the vault.
        _ibgtVault.stake(amount);
 
        /// *** Additional logic can be added here *** ///
    }
 
    /**
     * @notice Withdraw iBGT tokens from the vault.
     * @param amount uint256 The amount of iBGT tokens to withdraw.
     */
    function withdraw(uint256 amount) external {
        /// withdraw the iBGT tokens from the vault.
        _ibgtVault.withdraw(amount);
 
        /// transfer the iBGT tokens to the user.
        _ibgtToken.safeTransfer(msg.sender, amount);
 
        /// *** Additional logic can be added here *** ///
    }
 
    /**
     * @notice Claim rewards from the vault.
     */
    function claimRewards() external {
        /// claim the rewards from the vault.
        _ibgtVault.getReward();
 
        /// *** Additional logic can be added here *** ///
    }
 
    /**
     * @notice Harvest rewards from the vault.
     */
    function compoundRewards() external {
        uint256 balance = _ibgtToken.balanceOf(address(this));
        if (balance > 0) {
            /// deposit the iBGT tokens to the vault.
            _ibgtVault.stake(balance);
        } else {
            revert("No rewards to compound");
        }
    }
}