Flashloan

Flashloan tokens from the lending pool.

INIT offers a 0% fee flashloan for users to atomically use the available liquidity from lending pools to use elsewhere. The caller of flash function must be a contract that implements flashCallback function.

During the flashloan, the caller receives flashloan from lending pools and can execute arbitrary logic from bytes data through flashCallback which is called to the caller by InitCore. At the end of the flashloan, the caller must return the loan to the borrowed lending pools.

It is recommended to check that the sender is the InitCore in the flashCallback function to prevent unauthorized calls.

// Example Flashloan contract
contract FlashloanContract {
    function flashCallback(address[] calldata lendingPools, uint256[] calldata amounts, bytes calldata data) external {
        // check that the caller is InitCore
        require(msg.sender == INIT_CORE, 'unauthorized'); 
        
        // do some logic 
        
        // transfer back amounts to corresponding lending pools
    }
    
    function flash(address[] calldata lendingPools, uint256[] calldata amounts, bytes calldata data) external {
        // initiate flash loan
        IInitCore(INIT_CORE).flash(lendingPools, amounts, data);
    }
}

Last updated