Contract Integration

Interfaces

All of the necessary interfaces to interact with Verio protocol functions (staking and re-staking) can be found in the Integration repository.

Staking Examples

The following are some example contract integrations that utilize the staking function ComponentSelector and various protocol components.

Setup

import { IComponentSelector } from "path/to/staking/IComponentSelector.sol";
import { IStakePool } from "path/to/staking/IStakePool.sol";
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
// ...
address private constant VERIO_IP_COMPONENT_SELECTOR = address(0); // fill me in
// ...
IComponentSelector componentSelector = IComponentSelector(VERIO_IP_COMPONENT_SELECTOR);

Calculating vIP : IP Ratio

function _calculateVIPMintForStakeAmount(uint256 _ip) internal returns (uint256) {
    // calculate the amount of vIP to mint given an amount of IP
    return componentSelector.stakePool().calculateVIPMint(_ip);
}

Check vIP balance

function _vIPBalanceOf(address _holder) internal returns (uint256) {
    // get the vIP balance of the given holder
    return IERC20(componentSelector.verioIP()).balanceOf(_holder);
}

Staking

function stake() external payable {
    // calculate the expected vIP mint for this stake
    uint256 expectedVIPMint = _calculateVIPMintForStakeAmount(msg.value);
    // send stake to the stakePool
    componentSelector.stakePool().stake{value: msg.value}(true);
    // verify the vIP mint
    require(
        _vIPBalanceOf(address(this)) == expectedVIPMint,
        "Error, incorrect vIP mint"
    );
    // ...
}

Last updated