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 proportion is applied to the base operand and the result is returned in the base operand's units, so 50 percent of a token amount is a token amount. 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

    A caller-supplied parameter named weight is declared, filled in when the plug runs, so the weighting factor is not fixed here.

  2. 2·Take

    Next a parameter named total_value is declared, also provided by the caller at execution time.

  3. 3·Take

    A third parameter named price is declared, supplied by the caller when the plug runs.

  4. 4·Calculate proportional value

    Taking weight as a percentage of total_value computes a proportional slice of that total.

  5. 5·Set

    The result of that proportion is stored in a named variable called target_value for later reference.

  6. 6·Calculate

    Dividing target_value by the caller-supplied price returns the target_value expressed in units of price.

  7. 7·Set

    That quotient is stored in a named variable called target_balance.

  8. 8·Bubble

    The target_balance is surfaced as the output of this plug.

Take
Take
Take
Calculate of
Set to
Calculate
Set to
Bubble
  • Card: Buy $50 WBTC With USDC Once a Week

    time
    values
    math
  • Card: Buy an 18 Dec Token With X% of USDC

    plug
    evm
    math
  • Card: Sell X% of an 18 Dec Token for USDC

    plug
    evm
    math
  • Card: Sell 18 Dec Token for USDC

    plug
    chainlink
    math
  • Card: Sell 8 Dec Token for USDC

    plug
    chainlink
    math
  • Card: Buy 8 Dec Token With USDC

    plug
    chainlink
    values
  • Card: Buy 18 Dec Token With USDC

    plug
    chainlink
    values
  • Card: Sell 10% of ETH for USDC

    evm
    math
    chainlink
  • Card: Buy ETH With 10% of USDC

    evm
    math
    chainlink
  • Card: Sell $25 ETH for USDC

    values
    math
    chainlink
  • Card: Buy $25 ETH With USDC

    values
    math
    chainlink
  • 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
  • Swarm: Loop WETH/USDC at Target HF

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

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

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

    aave
    boolean
    evm