Borrow
Borrow

Morpho · Acts onchain

Borrows the loan asset from a Morpho Blue market against your supplied collateral. The market's parameters are resolved from its id and borrow is called for the exact asset amount, paid to the socket; the call returns the assets and shares borrowed. Morpho refuses it if the position would exceed the market's liquidation LTV. Set the amount to max to borrow the full capacity. Reach for it after supplying collateral in the same transaction, or to draw funds a following swap or deposit needs, holding the position's health factor above a floor with a predicate.

Morpho: Auto Leverage Trigger

plug
morpho
math
30actions
  1. 1·Take

    The caller supplies account at execution time, declared here as a named parameter for later steps to reference.

  2. 2·Take

    A market parameter is declared, its value provided by the caller when the plug runs.

  3. 3·Take

    triggerLTV is taken as a caller supplied value, the LTV threshold at which this plug should act.

  4. 4·Take

    targetLTV is declared as a caller supplied value, the LTV the position should be moved toward.

  5. 5·Take

    maxSlippage enters as a named parameter set by the caller at execution time.

  6. 6·Take

    numChunks is declared as a caller supplied parameter for later use.

  7. 7·Get market parameters

    Reading the Morpho Blue market at the identifier in the market slot pulls in its immutable configuration.

  8. 8·Get account data

    Your position in that market is read for the loan asset from slot 6.0.0, returning shares, collateral, debt, and health factor.

  9. 9·Get price

    The oracle price of the collateral in slot 6.0.1 is read in the loan asset for that market.

  10. 10·Calculate

    Slot 7.11.2 is multiplied by the position data from slot 8.5, producing a scaled quantity.

  11. 11·Calculate

    Slot 7.19 is divided by the oracle price, converting a value into price adjusted terms.

  12. 12·Compare two values

    A comparison checks whether the product from step 10 equals 0, returning a boolean.

  13. 13·Predicate

    This predicate requires that the quotient from step 11 is not equal to 0, since the target is false, halting if it does equal 0.

  14. 14·Calculate

    The triggerLTV is multiplied by the oracle price, scaling the threshold against the current price.

  15. 15·Compare two values

    A comparison tests whether the product from step 10 is less than the value in the market slot 2.0.

  16. 16·Compare two values

    Another comparison checks whether the triggerLTV scaled result from slot 13.0 is greater than slot 7.19.

  17. 17·Predicate

    This predicate requires slot 14.0 and slot 15.0 to both hold, gating execution on both conditions being true.

  18. 18·Calculate

    Slot 7.19 is subtracted from the triggerLTV scaled value in slot 13.0, giving a difference.

  19. 19·Calculate

    Slot 3.0 is subtracted from 1, computing the complement of the triggerLTV.

  20. 20·Calculate

    The difference from step 17 is divided by the difference from step 18, producing a ratio.

  21. 21·Calculate

    maxSlippage is floored at 1, clamping it to a minimum of that raw base unit value.

  22. 22·Calculate

    The complement from step 19 is divided by the ratio from step 20, yielding a sizing figure.

  23. 23·Flash loan

    A flash loan of the amount from slot 21.0 is drawn in the loan asset from slot 6.0.0, borrowed fee free and repaid within this transaction.

  24. 24·Calculate

    The flash loaned amount from slot 22.0 is divided by the position data in slot 8.5.

  25. 25·Calculate

    The targetLTV is subtracted from 1, computing its complement.

  26. 26·Calculate

    The flash loan sizing from slot 23.0 is multiplied by the targetLTV complement, producing a collateral amount.

  27. 27·Use

    Composing the Swap at Floor plug pulls its swap logic into this transaction.

  28. 28·Supply Collateral

    The swapped output from slot 26.0 is supplied as collateral in the collateral asset from slot 6.0.1 to the market.

  29. 29·Borrow

    The amount from slot 22.0 is borrowed in the loan asset from slot 6.0.0 against the supplied collateral, funding the flash loan repayment.

  30. 30·End block

    The open block is closed here, ending the gated sequence.

Take
Take
Take
Take
Take
Take
Get market parameters of
Get account data in of
Get price of in
Calculate
Calculate
Is
Calculate
Is
Is
Calculate
Calculate
Calculate
Calculate
Calculate
Flash loan
Calculate
Calculate
Calculate
Use where
accountis
sellAmountis
sellTokenis
buyTokenis
minReceiveis
Supply as collateral to
Borrow from
End block
  • Morpho: Auto Leverage Trigger

    plug
    morpho
    math
  • Morpho: Refinance to Cheaper Borrow Market

    morpho
    plug
    boolean

On other protocols · 4