Get market parameters
Get market parameters

Morpho · Reads onchain state

Reads a Morpho Blue market's immutable parameters. The market id resolves to its loan token, collateral token, oracle, interest rate model, and liquidation LTV at 18 decimals. These never change after creation. Reach for it when the market is chosen at runtime and later steps need the concrete token addresses to approve or swap, or the liquidation LTV to size a borrow a chosen distance below it.

Morpho: Auto Leverage Trigger

plug
morpho
math
30actions
  1. 1·Take

    The caller supplies account, the position owner this leverage adjustment acts on.

  2. 2·Take

    Next the caller supplies market, naming the Morpho Blue market the position sits in.

  3. 3·Take

    Then triggerLTV is taken, the loan-to-value level that must be reached before the plug fires.

  4. 4·Take

    Following that, targetLTV is taken, the loan-to-value the position is leveraged up toward.

  5. 5·Take

    The caller also supplies maxSlippage, the slippage bound the collateral swap must respect.

  6. 6·Take

    Rounding out the inputs, numChunks is taken, the count the plug uses to split the swap.

  7. 7·Get market parameters

    Reading the immutable parameters of the named market pulls in its loan token, collateral token, oracle, and fixed fields.

  8. 8·Get account data

    Fetching the account's position in that market against those parameters returns shares, collateral, debt, and health figures.

  9. 9·Get price

    Reading the market's oracle price gives its collateral token's value in the loan asset.

  10. 10·Calculate

    Multiplying the collateral figure by the oracle price values the held collateral in loan-asset terms.

  11. 11·Calculate

    Dividing the current debt by the oracle price expresses that debt in collateral terms.

  12. 12·Compare two values

    Testing the collateral value equal to 0 produces a boolean flagging an empty position.

  13. 13·Predicate

    Requiring the debt-over-price value equal 0 be false gates the flow, so it proceeds only with real debt present.

  14. 14·Calculate

    Multiplying triggerLTV by the oracle price scales the trigger threshold into the oracle's units.

  15. 15·Compare two values

    Comparing the collateral value less than triggerLTV checks whether the position sits below the trigger level.

  16. 16·Compare two values

    Comparing the scaled trigger against the debt-over-price value checks the threshold against current debt.

  17. 17·Predicate

    Requiring the scaled-trigger boolean and the below-trigger boolean together gates adjustment on both LTV conditions holding.

  18. 18·Calculate

    Subtracting the debt-over-price value from the scaled trigger gives the shortfall to close toward target.

  19. 19·Calculate

    Subtracting targetLTV from 1 yields the complement used to size the leverage step.

  20. 20·Calculate

    Dividing the combined boolean result by the shortfall begins computing the borrow amount.

  21. 21·Calculate

    Flooring maxSlippage at 1 clamps the slippage input to a minimum of 1.

  22. 22·Calculate

    Dividing the target complement by the prior quotient continues sizing the position adjustment.

  23. 23·Flash loan

    Taking a fee-free Morpho flash loan of the floored slippage value in the market's loan token, repaid within this transaction.

  24. 24·Calculate

    Dividing the sizing quotient by the oracle price converts the borrow amount into collateral terms.

  25. 25·Calculate

    Subtracting targetLTV from 1 yields the complement again for the swap sizing.

  26. 26·Calculate

    Multiplying the flash-loan amount by the collateral-terms quotient produces the collateral quantity to acquire.

  27. 27·Use

    Composing the Swap at Floor plug routes the swap that acquires collateral under the floor logic.

  28. 28·Supply Collateral

    Supplying that acquired collateral amount of the collateral token to the named market builds the position.

  29. 29·Borrow

    Borrowing the sizing quotient of loan token from the named market against the supplied collateral funds repayment.

  30. 30·End block

    Closing the innermost open block completes the composed leverage transaction.

Take
Take
Take
Take
Take
Take
Get market parameters of
Get 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
  • Pendle Leveraged PT Auto Rollover

    plug
    pendle
    time
  • Morpho: Leverage Manager

    values
    morpho
    evm
  • Morpho: Auto Leverage Trigger

    plug
    morpho
    math
  • Morpho: Refinance to Cheaper Borrow Market

    morpho
    plug
    boolean
  • Morpho: Check Refinancing Constraints

    plug
    morpho
    evm
  • Morpho Pendle Expiry Deleveraging

    pendle
    time
    boolean