Multiply then divide
Multiply then divide

Math · Reads onchain state

Multiplies two values and divides by a third in one step, rounding up or down. Dividing after the multiply avoids the truncation of a separate divide-then-multiply, so fixed-point ratios like utilization stay wei-exact, while round-up matches protocol share math that rounds debt up. The x × y intermediate is a checked 256-bit product: the call reverts if it overflows uint256, and reverts on z = 0. All three operands are reconciled to eighteen decimals, so the divisor is the measured value you are dividing by and not a scale word: the WAD constant here is the number one and divides by nothing. Where a raw denominator really is wanted, write it as a literal. Reach for it to convert an amount across a price or rate, such as collateral times price divided by that price's own denominator, or to scale a balance by a share ratio without losing precision.

Expected Amount to Minimum Received

plug
math
values
6actions
  1. 1·Take

    Opening by declaring expected_amount, this parameter is left for the caller to supply at execution time, naming the baseline quantity the slippage floor applies to.

  2. 2·Take

    A second parameter, max_slippage, is declared as caller-supplied, giving the tolerance fraction that will be subtracted from full scale.

  3. 3·Calculate

    Subtracting max_slippage from 1 produces the retained fraction, the share of expected_amount that survives after slippage.

  4. 4·Get constant

    Holding WAD (1e18) as a named constant provides the scale factor for the fixed-point multiply-divide that follows.

  5. 5·Multiply then divide

    Multiplying expected_amount by the retained fraction and dividing by WAD, rounded down, yields the minimum received figure at the given slippage.

  6. 6·Bubble

    Surfacing that quotient returns the computed minimum received amount as the output of this plug.

Take
Take
Calculate
Get constant
Calculate times divided by rounded
Bubble
  • Expected Amount to Minimum Received

    plug
    math
    values
  • Raw Weights to Percents

    plug
    evm
    boolean
  • Get Weight Target

    plug
    values
    math
  • Morpho: Get Health Factor

    plug
    boolean
    evm
  • Morpho: Borrow Shares to Borrow Assets

    plug
    math
    evm