
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



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·Take
Next a parameter named total_value is declared, also provided by the caller at execution time.
3·Take
A third parameter named price is declared, supplied by the caller when the plug runs.
4·Calculate proportional value
Taking weight as a percentage of total_value computes a proportional slice of that total.
5·Set
The result of that proportion is stored in a named variable called target_value for later reference.
6·Calculate
Dividing target_value by the caller-supplied price returns the target_value expressed in units of price.
7·Set
That quotient is stored in a named variable called target_balance.
8·Bubble
The target_balance is surfaced as the output of this plug.