Get constant

Get constant on Values

Ethereum
Ethereum
Base
Base

Reads onchain state

Ready to run on Base

Holds a well-known constant as a named value: max uint256, WAD, RAY, basis points, one, or zero. Each one is echoed into a slot carrying its own decimal tag, so it is a measured value rather than a raw scale word: WAD is one at eighteen decimals, RAY is one at twenty-seven, basis points is one at four. Anything that reconciles against it therefore divides by one. A slot that genuinely wants the raw word 1000000000000000000 has to be written as that literal, because a literal declares no scale and stays whole. Reach for it to state a bound or a sentinel, such as max uint256 as an unlimited amount or zero as an empty floor, rather than to hand a calculation a scale it already reconciles for you.

Plug lets you combine onchain actions like this one into a single transaction, without writing a smart contract. Use in App opens a new plug with this action already in it.

Get Weight Target

plug
values
math
6actions
  1. 1·Take

    Opening by declaring token, this parameter is left for the caller to supply at execution time, naming the asset whose moving average will be measured.

  2. 2·Take

    A second parameter, window, is declared as caller-supplied, setting the lookback period passed into the average calculation.

  3. 3·Use

    Composing the Get Simple Moving Average plug runs that sub-plug on the token over the window, producing the raw average value.

  4. 4·Get constant

    Holding WAD (1e18) as a named constant provides the scale factor for the fixed-point multiply-divide that follows.

  5. 5·Multiply then divide

    Multiplying the moving average by WAD and dividing by the second output of the average plug, rounded down, yields the scaled weight target.

  6. 6·Bubble

    Surfacing that quotient returns the computed weight target as the output of this plug.

Take
Take
Use where
tokenis
windowis
Get constant
Calculate times divided by rounded
Bubble

More plugs on Base

Bridge from Base · 6 plugs

Posts · 1

More on Values · 6