Get market parameters

Get market parameters on Morpho

Ethereum
Ethereum
Base
Base

Reads onchain state

Ready to run on Base

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.

Plug lets you combine onchain actions like this one into a single transaction, without writing a smart contract. Use in App opens a new plug with this action already in it.

Morpho: Auto Leverage Trigger

plug
morpho
math
30actions
  1. 1·Take

    The caller supplies account, naming the position owner this leverage adjustment acts on at execution time.

  2. 2·Take

    Next market is taken, naming the Morpho Blue market whose position the plug will adjust.

  3. 3·Take

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

  4. 4·Take

    Following that, targetLTV is taken, the loan-to-value the position is moved toward once triggered.

  5. 5·Take

    Taking maxSlippage declares the slippage bound the caller accepts on the swap leg.

  6. 6·Take

    Rounding out the inputs, numChunks is taken, the count the floor step below uses.

  7. 7·Get market parameters

    Immutable parameters of the named market are read, pulling in its loan token, collateral token, oracle, and fixed fields.

  8. 8·Get account data

    Your wallet's position in that market against those parameters is read, giving shares, collateral, supplied assets, debt, and health.

  9. 9·Get price

    The market's oracle price of its collateral token in its loan asset is read.

  10. 10·Calculate

    A fixed field from the market parameters is multiplied by the collateral figure from the position read.

  11. 11·Calculate

    The position's debt figure is divided by the oracle price, converting debt into collateral-denominated terms.

  12. 12·Compare two values

    Testing whether the first product equals 0 yields a flag on that computed quantity.

  13. 13·Predicate

    Requiring the debt-over-price quotient equal 0 be false gates the flow on that quotient being nonzero.

  14. 14·Calculate

    The triggerLTV input is multiplied by the oracle price, scaling the trigger level into priced terms.

  15. 15·Compare two values

    Comparing the first product against triggerLTV tests whether that product is below the trigger level.

  16. 16·Compare two values

    Comparing the triggerLTV-times-price result against the debt-over-price quotient tests whether it is greater.

  17. 17·Predicate

    Requiring the trigger-times-price result and the earlier comparison both hold gates the adjustment on both conditions.

  18. 18·Calculate

    Subtracting the debt-over-price quotient from the trigger-times-price result yields a collateral-denominated difference.

  19. 19·Calculate

    Subtracting the triggerLTV-times-price result from 1 yields the complement of that scaled level.

  20. 20·Calculate

    Dividing the step-17 and comparison result by that complement produces a sized quantity.

  21. 21·Calculate

    Flooring maxSlippage at 1 sets a lower bound of 1 on the slippage value.

  22. 22·Calculate

    Dividing the step-19 complement by the step-20 quotient produces the flash-loan sizing figure.

  23. 23·Flash loan

    A fee-free Morpho flash loan is taken for the floored maxSlippage amount in the loan token, repaid within this transaction.

  24. 24·Calculate

    Dividing the step-22 sizing figure by the collateral figure normalizes it against held collateral.

  25. 25·Calculate

    Subtracting targetLTV from 1 yields the complement of the target loan-to-value.

  26. 26·Calculate

    Multiplying the flash-loan amount by the step-24 quotient sizes the collateral to acquire.

  27. 27·Use

    Composing the Swap at Floor plug routes the swap leg for the leveraged position.

  28. 28·Supply Collateral

    The step-26 product is supplied as collateral in the market's collateral token to the named market.

  29. 29·Borrow

    The step-22 sizing figure is borrowed as loan token from the named market against the new collateral.

  30. 30·End block

    The remaining open block is closed, ending the 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

More plugs on Base

Borrow on Base · 7 plugs

Posts · 7

More on Morpho · 16