Skip to main content

PythPriceOracle

Git Source

Inherits: IPriceOracle

Title: PythPriceOracle

Author: SocksNFlops

The PythPriceOracle contract is a contract that tracks the price of a given asset to determine the trigger price for conversions.

State Variables

USD_DECIMALS

The number of decimals for USD

int8 public constant USD_DECIMALS = 18

MAX_AGE

The maximum age of a price in seconds

uint32 public constant MAX_AGE = 60 seconds

pyth

The Pyth contract

IPyth public immutable pyth

pythPriceId

The Pyth price ID

bytes32 public immutable pythPriceId

maxConfidence

The maximum confidence

uint256 public immutable maxConfidence

collateralDecimals

The number of decimals for the collateral

uint8 public immutable collateralDecimals

Functions

constructor

Constructor

constructor(address pyth_, bytes32 priceId_, uint256 maxConfidence_, uint8 collateralDecimals_) ;

Parameters

NameTypeDescription
pyth_addressThe address of the Pyth contract
priceId_bytes32The Pyth price ID
maxConfidence_uint256The maximum confidence
collateralDecimals_uint8The number of decimals for the collateral

price

Returns the price of the collateral in USDX

function price() public view override returns (uint256 assetPrice);

Returns

NameTypeDescription
assetPriceuint256The price of the collateral in USDX (18 decimals)

cost

Returns the cost of the collateral in USDX

function cost(uint256 collateralAmount) public view override returns (uint256 totalCost, uint8 _collateralDecimals);

Parameters

NameTypeDescription
collateralAmountuint256The amount of collateral to calculate the cost of

Returns

NameTypeDescription
totalCostuint256The cost of the collateral in USDX (18 decimals)
_collateralDecimalsuint8The collateral decimals

Errors

MaxAgeExceeded

The error thrown when the age of a price is greater than the maximum age

error MaxAgeExceeded(uint256 age, uint256 maxAge);

Parameters

NameTypeDescription
ageuint256The age of the price
maxAgeuint256The maximum age

MaxConfidenceExceeded

The error thrown when the confidence of a price is greater than the maximum confidence

error MaxConfidenceExceeded(uint256 confidence, uint256 maxConfidence);

Parameters

NameTypeDescription
confidenceuint256The confidence of the price
maxConfidenceuint256The maximum confidence