Skip to main content

Module oracle

Module oracle 

Source
Expand description

Oracle decimal conversion utilities.

Different oracle providers use different decimal precisions:

  • Chainlink: 8 decimals for most feeds, 18 for some
  • Pyth: Variable precision (exponent-based)
  • RedStone: 8 decimals
  • Band Protocol: 18 decimals

This module provides utilities for normalizing and converting between different oracle decimal formats.

Enums§

OracleDecimals
Standard oracle decimal formats.

Functions§

calculate_value
Calculate the value of tokens in a quote currency.
calculate_value_i128
Calculate value and return as i128 for large results.
convert_decimals
Convert a price between two different decimal precisions.
convert_decimals_i128
Convert a price between decimal precisions, returning i128.
denormalize_oracle_price
Convert a Decimal to a raw oracle integer value.
denormalize_oracle_price_i128
Convert a Decimal to a raw oracle i128 value.
normalize_oracle_price
Normalize a raw oracle value to a Decimal.
normalize_oracle_price_i128
Normalize a large raw oracle value to a Decimal.
normalize_pyth_price
Normalize a Pyth-style price with exponent.
scale_token_amount
Scale a token amount between different decimal precisions.
scale_token_amount_i128
Scale a token amount using i128 for large values.