A closer look at the integration between IbAlluo and StIbAlluo

Here we dive into the IbAlluo - StIbAlluo integration

Whenever tokens are burnt or transferred (any deduction from a user's IbAlluo balance, the IbAlluo.sol contract makes a check if the amount to be moved is greater than their current IbAlluo balance and whether it is possible to unwrap the difference from the StIbAlluo balance.

  • For example, a user has 50 IbAlluos and 50 StIbAlluos from a CFA. If they called the ERC-20 Transfer to another user for 70 IbAlluos, the IbAlluo contract unwraps 20 StIbAlluos and then carries out the transaction without reverting, even if they had 50 IbAlluos - leaving them with 0 IbAlluos and 30 StIbAlluos.

This is carried out through ERC777 methods implemented in the Super token interface as the IbAlluo is set as a default operator for the StIbAlluo contract. See the functions below.

function _burn(address account, uint256 amount) internal override {
         // If there are insufficient tokens in IbAlluo, check if we can
         // burn StIbAlluo instead and carry on. If insufficient, revert.
        if (amount > balanceOf(account)) {
            IAlluoSuperToken(superToken).operatorBurn(account, amount - balanceOf(account), "", "");
        super._burn(account, amount);

 function _transfer(address from, address to, uint256 amount) internal override {
         // Similar to the logic above
        if (amount > balanceOf(from)) {
            IAlluoSuperToken(superToken).operatorBurn(from, amount - balanceOf(from), "", "");
        super._transfer(from, to, amount);

Similarly, the two view functions above return the combined balance of IbAlluo and StIbAlluo a user has. getBalance() returns it in USD value, while combinedBalanceOf() returns it as a basic sum.

  • If you only want the balance of IbAlluos a user has, use the standard ERC-20 balanceOf() function.

/// @notice  Returns balance in asset value
/// @param _address address of user
function getBalance(address _address) public view returns (int256) {
    uint256 _growingRatio = changeRatio(
    (int256 StIbAlluoBalance,,,) = IAlluoSuperToken(superToken).realtimeBalanceOfNow(_address);
    int256 fullBalance = int256(balanceOf(_address)) + StIbAlluoBalance;
    return (fullBalance * int256(_growingRatio) / int256(multiplier));

/// @notice  Returns combined StIbAlluo and IbAlluo balance 
/// @param _address address of user
/// @dev This is necessary for users with both IbAlluo and StIbAlluo balances so that the frontend and other contracts can accurately calculate balances.
function combinedBalanceOf(address _address) public view returns (int256) {
    (int256 StIbAlluoBalance,,,) = IAlluoSuperToken(superToken).realtimeBalanceOfNow(_address);
    return int256(balanceOf(_address)) + StIbAlluoBalance;

Last updated