Get price
Get price

Morpho · Reads onchain state

Reads a Morpho Blue market's oracle price of its collateral in its loan asset. The market's oracle is resolved from its parameters and the price of one whole collateral token returned in whole loan tokens at 18 decimals: the same number the market uses when it checks a position's LTV, on a scale that does not move with the pair's decimals. Reach for it to convert collateral into borrowing capacity, to size a repay against collateral value, or to detect a move between runs by comparing against a stored value.

Morpho: Auto Leverage Trigger

plug
morpho
math
30actions
  1. 1·Take

    The caller supplies account, naming the position owner this trigger evaluates and 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 exceeded before the trigger acts.

  4. 4·Take

    Following that, targetLTV is taken, the loan-to-value the adjustment aims to reach.

  5. 5·Take

    Rounding out the risk inputs, maxSlippage is taken to bound the swap price tolerance.

  6. 6·Take

    Last of the inputs, numChunks is taken to split the swap into pieces.

  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 your position in that market returns shares, collateral, debt, and health figures for the account.

  9. 9·Get price

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

  10. 10·Calculate

    Multiplying a fixed field from the market parameters by the collateral figure sizes the collateral's value against that field.

  11. 11·Calculate

    Dividing the position's debt figure by the oracle price converts the debt into collateral-denominated terms.

  12. 12·Compare two values

    Testing whether the multiplied value equals 0 returns a boolean about that product.

  13. 13·Predicate

    Requiring the debt-over-price ratio equal 0 be false gates the flow, so it proceeds only when debt exists.

  14. 14·Calculate

    Multiplying triggerLTV by the oracle price produces the trigger threshold in the same terms as the priced values.

  15. 15·Compare two values

    Comparing the multiplied collateral value against market against the position's health confirms one condition holds.

  16. 16·Compare two values

    Checking whether the trigger threshold is greater than the debt-over-price ratio tests whether the LTV trigger has fired.

  17. 17·Predicate

    Requiring the collateral-value comparison and the trigger comparison both hold gates the adjustment on both conditions.

  18. 18·Calculate

    Subtracting the debt-over-price ratio from the trigger threshold measures the gap between them.

  19. 19·Calculate

    Subtracting triggerLTV from 1 yields the complement of the trigger level.

  20. 20·Calculate

    Dividing the trigger-comparison result by that complement scales the gap toward the target.

  21. 21·Calculate

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

  22. 22·Calculate

    Dividing the trigger complement by the prior quotient sizes the amount to borrow for the leverage step.

  23. 23·Flash loan

    Taking a fee-free Morpho flash loan of that sized amount in the market's loan token, repaid within this transaction.

  24. 24·Calculate

    Dividing the flash-loan-derived amount by the collateral figure converts it into collateral-denominated terms.

  25. 25·Calculate

    Subtracting targetLTV from 1 yields the complement of the target level.

  26. 26·Calculate

    Multiplying the converted amount by the target complement sizes the collateral to supply.

  27. 27·Use

    Composing the Swap at Floor plug routes the flash-loaned loan token into collateral at the floored slippage bound.

  28. 28·Supply Collateral

    Supplying that sized collateral to the market lends the collateral token to build the position.

  29. 29·Borrow

    Borrowing the flash-loan amount of loan token from the market against the supplied collateral funds repayment of the flash loan.

  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 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: Check Refinancing Constraints

    plug
    morpho
    evm
  • Morpho Pendle Expiry Deleveraging

    pendle
    time
    boolean

On other protocols · 8