Skip to content

Infrared iBGT Vault Integration

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.

Install the required contracts:

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

Import the required contracts:

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

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);
    }

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 *** ///
    }

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 *** ///
    }

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");
        }
    }

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");
        }
    }
}