
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



1·Take
Weight is declared as a caller supplied parameter, its figure handed in at execution time.
2·Take
A second parameter, total_value, is declared for the caller to provide when the plug runs.
3·Take
Price is declared as a third caller supplied parameter, named for supply at execution time.
4·Calculate proportional value
Taking weight as a percent proportion of total_value, this computes the portion of total value assigned to that weight.
5·Set
That computed proportion is assigned to a named variable, target_value, holding it for later steps.
6·Calculate
Dividing target_value by price converts the target value into token units.
7·Set
The quotient is assigned to target_balance, naming the balance the target value implies.
8·Bubble
Finally, target_balance is surfaced as the output of this plug.