
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



1·Take
The caller supplies account, naming the position owner this trigger evaluates and acts on.
2·Take
Next the caller supplies market, naming the Morpho Blue market the position sits in.
3·Take
Then triggerLTV is taken, the loan-to-value level that must be exceeded before the trigger acts.
4·Take
Following that, targetLTV is taken, the loan-to-value the adjustment aims to reach.
5·Take
Rounding out the risk inputs, maxSlippage is taken to bound the swap price tolerance.
6·Take
Last of the inputs, numChunks is taken to split the swap into pieces.
7·Get market parameters
Reading the immutable parameters of the named market pulls in its loan token, collateral token, oracle, and fixed fields.
8·Get account data
Fetching your position in that market returns shares, collateral, debt, and health figures for the account.
9·Get price
Reading the market's oracle price gives the collateral token's value in the loan asset.
10·Calculate
Multiplying a fixed field from the market parameters by the collateral figure sizes the collateral's value against that field.
11·Calculate
Dividing the position's debt figure by the oracle price converts the debt into collateral-denominated terms.
12·Compare two values
Testing whether the multiplied value equals 0 returns a boolean about that product.
13·Predicate
Requiring the debt-over-price ratio equal 0 be false gates the flow, so it proceeds only when debt exists.
14·Calculate
Multiplying triggerLTV by the oracle price produces the trigger threshold in the same terms as the priced values.
15·Compare two values
Comparing the multiplied collateral value against market against the position's health confirms one condition holds.
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·Predicate
Requiring the collateral-value comparison and the trigger comparison both hold gates the adjustment on both conditions.
18·Calculate
Subtracting the debt-over-price ratio from the trigger threshold measures the gap between them.
19·Calculate
Subtracting triggerLTV from 1 yields the complement of the trigger level.
20·Calculate
Dividing the trigger-comparison result by that complement scales the gap toward the target.
21·Calculate
Flooring maxSlippage at 1 clamps the slippage input to a lower bound of 1.
22·Calculate
Dividing the trigger complement by the prior quotient sizes the amount to borrow for the leverage step.
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·Calculate
Dividing the flash-loan-derived amount by the collateral figure converts it into collateral-denominated terms.
25·Calculate
Subtracting targetLTV from 1 yields the complement of the target level.
26·Calculate
Multiplying the converted amount by the target complement sizes the collateral to supply.
27·Use
Composing the Swap at Floor plug routes the flash-loaned loan token into collateral at the floored slippage bound.
28·Supply Collateral
Supplying that sized collateral to the market lends the collateral token to build the position.
29·Borrow
Borrowing the flash-loan amount of loan token from the market against the supplied collateral funds repayment of the flash loan.
30·End block
Closing the innermost open block completes the composed leverage transaction.