
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
First, weight is declared as a caller supplied parameter, its value handed in at execution time.
2·Take
Next, total_value is declared as a second caller supplied parameter, taken at execution time.
3·Take
A third parameter, price, is declared for the caller to supply at execution time.
4·Calculate proportional value
Taking weight as a 100 percent proportion of total_value, this computes a proportional slice of the supplied value.
5·Set
That proportional slice is assigned to a named variable, target_value, holding it for the next step.
6·Calculate
Dividing target_value by price, this converts the value into a balance in token units.
7·Set
The quotient is saved as target_balance, holding the computed figure for output.
8·Bubble
Finally, target_balance is surfaced as the output of this plug.