API ReferencePricing and oraclesInterface
Price
Represents the output per unit input price between two tokens. That is to say the whole integer value price from one token to another, regardless of ERC-20 decimals a token has. ERC-20 decimals is simply a display concept that muddies the waters for calculations since all values are stored on the blockchain as integers.
The benefit of this approach is that you may convert from one token’s value to another token’s value without having to ask the token contract how many decimals each token has because that is baked into the price.
Example: Token A decimals: 10 Token B decimals: 5 1 whole A = 1 whole B Example A per unit B price: { price: 1 exponent: 5 publishTime: 12345678 }
Properties
exponent
exponent: bigint;The base-10 exponent by which price must be scaled (price * 10 ** exponent).
price
price: bigint;Integer significand. price * 10 ** exponent is the number of smallest units of the output token
per one smallest unit of the input token — both tokens’ decimals are already folded in, so rescale
only for display.
publishTime
publishTime: bigint;Unix second timestamp describing when the price was published.