📚
INIT Capital Developer Docs
  • Overview
  • Core Contracts
  • Guides
    • Basic Interaction
      • Deposit and Withdraw
      • Create Position
      • Add and Remove Collateral
      • Borrow and Repay
      • Changing Position Mode
    • Advanced Interaction
      • Liquidate Position
      • Flashloan
      • Multicall
      • Callback
    • Liquidity Hook
      • Multicall with Callback
      • Money Market Hook
      • Looping Hook
      • Margin Trading Hook
  • Contract References
    • InitCore
    • PosManager
    • LendingPool
    • Config
    • RiskManager
    • InitOracle
    • LiqIncentiveCalculator
    • DoubleSlopeIRM
    • InitErrors
    • MoneyMarketHook
    • LoopingHook
    • MarginTradingHook
  • Contract Addresses
    • Blast
    • Mantle
Powered by GitBook
On this page
  1. Guides
  2. Advanced Interaction

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);
    }
}

PreviousLiquidate PositionNextMulticall

Last updated 1 year ago