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.
IbAlluo.sol
1
function _burn(address account, uint256 amount) internal override {
2
// If there are insufficient tokens in IbAlluo, check if we can
3
// burn StIbAlluo instead and carry on. If insufficient, revert.
4
if (amount > balanceOf(account)) {
5
IAlluoSuperToken(superToken).operatorBurn(account, amount - balanceOf(account), "", "");
6
}
7
super._burn(account, amount);
8
}
9
10
function _transfer(address from, address to, uint256 amount) internal override {
11
// Similar to the logic above
12
if (amount > balanceOf(from)) {
13
IAlluoSuperToken(superToken).operatorBurn(from, amount - balanceOf(from), "", "");
14
}
15
super._transfer(from, to, amount);
16
}
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(
growingRatio,
interestPerSecond,
lastInterestCompound
);
(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;
}

liquidity-direction-protocol/StIbAlluo.sol at StIbAlluo · GetAlluo/liquidity-direction-protocol
GitHub
To read the lastest StIbAlluo code

liquidity-direction-protocol/IbAlluo.sol at StIbAlluo · GetAlluo/liquidity-direction-protocol
GitHub
To read the latest IbAlluodcode