Alluo Explained
Search
K

Using the IbAlluo contract directly to create streams

Creating a stream directly through the IbAlluo contract allows you to bypass manually wrapping and approving the StIbAlluo contract.

1. Grant Permissions first!

To do so, you must grant permissions to the IbAlluo contract as a stream operator for your account. One way you can do this is through hardhat by instantiating an IbAlluo contract, using formatPermissions to get the callData and then calling the Superfluid Host contract with the following parameters. This only needs to be done once for each IbAlluo contract when initially making a stream.
IbAlluo.sol
1
/// @notice Formats permissios so users can approve the ibAlluo contract as an operator of streams
2
/// @dev This can be removed once the frontend hardcodes the function call / does it inside ethers.js.
3
function formatPermissions() public view returns (bytes memory) {
4
return abi.encodeCall(
5
cfaV1Lib.cfa.authorizeFlowOperatorWithFullControl,
6
(
7
ISuperfluidToken(superToken),
8
address(this),
9
new bytes(0)
10
)
11
);
12
}
Example on polygon
1
let encodeData = await ibAlluoCurrent.formatPermissions();
2
let superhost = await ethers.getContractAt("Superfluid", "0x3E14dC1b13c488a8d5D310918780c983bD5982E7");
3
await superhost.callAgreement(
4
"0x6EeE6060f715257b970700bc2656De21dEdF074C",
5
encodeData,
6
"0x"
7
)

2. Once permissions are granted, now call the createFlow function

IbAlluo.sol
1
/// @notice Wraps and creates flow
2
/// @dev Forces transfer of ibAlluo to the StIbAlluo contract then mints StIbAlluos to circumvent having to sign multiple transactions to create streams
3
/// @param receiver The recipient of the streamed flow
4
/// @param flowRate The amount of ibAlluos per second to be streamed (decimals 10**18)
5
/// @param toWrap The amount of ibAlluos to automatically wrap (recommend wrapping entire ibALluo balance initially)
6
function createFlow(address receiver, int96 flowRate, uint256 toWrap) external {
7
_transfer(msg.sender, address(this), toWrap);
8
_approve(address(this), superToken, toWrap);
9
IAlluoSuperToken(superToken).upgradeTo(msg.sender, toWrap, "");
10
cfaV1Lib.createFlowByOperator( msg.sender, receiver, ISuperfluidToken(superToken), flowRate);
11
ISuperfluidResolver(superfluidResolver).addToChecker(msg.sender, receiver);
12
emit CreateFlow(msg.sender, receiver, flowRate);
13
}
14
function stopFlowWhenCritical(address sender, address receiver) external onlyRole(DEFAULT_ADMIN_ROLE) {
15
cfaV1Lib.deleteFlowByOperator(sender, receiver, ISuperfluidToken(superToken));
16
emit DeletedFlow(sender, receiver);
17
}
18
19
function forceWrap(address sender) external onlyRole(DEFAULT_ADMIN_ROLE) {
20
uint256 balance = balanceOf(address(sender));
21
_transfer(sender, address(this), balance);
22
_approve(address(this), superToken, balance);
23
IAlluoSuperToken(superToken).upgradeTo(sender, balance, "");
24
}
Calling createFlow will force transfer IbAlluos and then the IbAlluo contract will upgrade on your behalf and mint you StIbAlluos. Then, a flow will be created with the parameters you specified.
When creating a stream through the IbAlluo contract, the Alluo protocol protects you from liquidations: addToChecker() adds you to a list of users that a gelato resolver will check for liquidation risk. This means that whenever your StIbAlluo balance is low, a resolver will either call forceWrap() so you don't get accidentally liquidated, or close the stream entirely using stopFlowWhenCritical().
To illustrate this with examples:
  • Case 1: Stream close to liquidation but with enough IbAlluo balance to cover it.
You have 100 IbAlluos and 100 StIbAlluos with an outgoing stream of 20 IbAlluos per hour. You are 1 hour away from being liquidated by the superfluid protocol (including the deposit initially taken).
The Alluo resolver will realise that you have 100 IbAlluo to continue the stream and therefore wrap the IbAlluo to StIbAlluo - leaving you with 0 IbAlluo and 200 StIbAlluo to continue the stream.
  • Case 2: Stream close to liquidation but without enough IbAlluo balance to cover it.
You have 0 IbAlluos and 100 StIbAlluos with an outgoing stream of 20 IbAlluos per hour. You are 1 hour away from being liquidated by the superfluid protocol (including the deposit initially taken). The Alluo protocol will close your stream 1 hour prematurely to prevent your 80 StIbAlluos from being taken as a liquidation fee.