Calculate proportional value
Calculate proportional value

Math · Reads onchain state

Calculates a proportion of a value using percent, basis points, WAD, or RAY units. The operand and its unit are a ratio, so both stay raw words and the base carries the scale: the base is taken to 18 decimals for the arithmetic and the result is stated at 18 decimals. A step that consumes it carries the word back into its own units, so 50 percent of a USDC balance supplies as that many USDC. Reach for it to size a partial action: withdraw a fixed percentage of a position, repay a share of debt, or split a balance by basis points across two destinations.

Get Target Balance

plug
math
evm
8actions
  1. 1·Take

    First, weight is declared as a caller supplied parameter, its value handed in at execution time.

  2. 2·Take

    Next, total_value is declared as a second caller supplied parameter, taken at execution time.

  3. 3·Take

    A third parameter, price, is declared for the caller to supply at execution time.

  4. 4·Calculate proportional value

    Taking weight as a 100 percent proportion of total_value, this computes a proportional slice of the supplied value.

  5. 5·Set

    That proportional slice is assigned to a named variable, target_value, holding it for the next step.

  6. 6·Calculate

    Dividing target_value by price, this converts the value into a balance in token units.

  7. 7·Set

    The quotient is saved as target_balance, holding the computed figure for output.

  8. 8·Bubble

    Finally, target_balance is surfaced as the output of this plug.

Take
Take
Take
Calculate of
Set to
Calculate
Set to
Bubble
  • Get Target Balance

    plug
    math
    evm
  • Morpho: Collateral Value to Borrow Capacity

    plug
    math
    evm
  • Wind or Unwind to Maintain Target HF

    plug
    aave
    math
  • Loop WETH/USDC at Target HF

    aave
    evm
    boolean
  • Loop at Target HF + Borrow Rate Exit Guard

    database
    boolean
    aave
  • Loop at Target HF + Borrow Rate Entry & Exit Guard

    aave
    boolean
    evm
  • Loop at Target HF + Trailing Stop Loss

    database
    boolean
    aave
  • Swarm: Loop WETH/USDC at Target HF

    boolean
    aave
    evm