InfraredVault
How to integrate InfraredVault into your platform.
This product is attractive to protocols looking to retain Berachain and Infrared incentives when integrating various LP tokens, ie HONEY/WBERA
LP tokens. It is important that protocols maximize these efficiencies to ensure the best possible yield for their users. This integration looks at a contract that stakes liquidity receiving iBGT and HONEY
.
Steps
1. Install the required contracts
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 ExampleLPVaultIntegration contract.
* @param lpVault address The address of the LP token vault.
* @param lpToken address The address of the LP token.
* @param ibgtVault address The address of the iBGT vault.
* @param ibgtToken address The address of the iBGT token.
*/
constructor(address lpVault, address lpToken, address ibgtVault, address ibgtToken) {
_lpVault = InfraredVault(lpVault);
_lpToken = IERC20(lpToken);
_ibgtVault = InfraredVault(ibgtVault);
_ibgtToken = IERC20(ibgtToken);
_lpToken.approve(address(_lpVault), type(uint256).max);
}
4. Allow users to deposit LP tokens and stake them
/**
* @notice Deposit LP tokens to the vault.
* @param amount uint256 The amount of LP tokens to deposit.
*/
function deposit(uint256 amount) external {
/// require that the user has approved the contract to spend their LP tokens.
_lpToken.safeTransferFrom(msg.sender, address(this), amount);
/// deposit the LP tokens to the vault.
_lpVault.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.
_lpVault.getReward();
/// *** Additional logic can be added here *** ///
}
6. Withdraw LP tokens from the vault
/**
* @notice Withdraw LP tokens from the vault.
* @param amount uint256 The amount of LP tokens to withdraw.
*/
function withdraw(uint256 amount) external {
/// withdraw the LP tokens from the vault.
_lpVault.withdraw(amount);
/// transfer the LP tokens to the user.
_lpToken.safeTransfer(msg.sender, amount);
/// *** Additional logic can be added here *** ///
}
Full example
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 ExampleLPVaultIntegration {
using SafeERC20 for IERC20;
/// @notice the LP token vault.
InfraredVault private immutable _lpVault;
/// @notice LP token.
IERC20 private immutable _lpToken;
/// @notice the iBGT vault.
InfraredVault private immutable _ibgtVault;
/// @notice the iBGT token.
IERC20 private immutable _ibgtToken;
/**
* @notice Construct the ExampleLPVaultIntegration contract.
* @param lpVault address The address of the LP token vault.
* @param lpToken address The address of the LP token.
* @param ibgtVault address The address of the iBGT vault.
* @param ibgtToken address The address of the iBGT token.
*/
constructor(address lpVault, address lpToken, address ibgtVault, address ibgtToken) {
_lpVault = InfraredVault(lpVault);
_lpToken = IERC20(lpToken);
_ibgtVault = InfraredVault(ibgtVault);
_ibgtToken = IERC20(ibgtToken);
_lpToken.approve(address(_lpVault), type(uint256).max);
}
/**
* @notice Deposit LP tokens to the vault.
* @param amount uint256 The amount of LP tokens to deposit.
*/
function deposit(uint256 amount) external {
/// require that the user has approved the contract to spend their LP tokens.
_lpToken.safeTransferFrom(msg.sender, address(this), amount);
/// deposit the LP tokens to the vault.
_lpVault.stake(amount);
/// *** Additional logic can be added here *** ///
}
/**
* @notice Withdraw LP tokens from the vault.
* @param amount uint256 The amount of LP tokens to withdraw.
*/
function withdraw(uint256 amount) external {
/// withdraw the LP tokens from the vault.
_lpVault.withdraw(amount);
/// transfer the LP tokens to the user.
_lpToken.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.
_lpVault.getReward();
/// claim the rewards from the iBGT vault.
_ibgtVault.getReward();
/// *** Additional logic can be added here *** ///
}
/**
* @notice stake iBGT tokens.
*/
function stakeIBGT() external {
uint256 balance = _ibgtToken.balanceOf(address(this));
if (balance > 0 ) {
/// deposit the iBGT tokens to the vault.
_ibgtVault.stake(balance);
} else revert ("No iBGT tokens to stake");
/// *** Additional logic can be added here *** ///
}
}