PythPriceOracle
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
| Name | Type | Description |
|---|---|---|
pyth_ | address | The address of the Pyth contract |
priceId_ | bytes32 | The Pyth price ID |
maxConfidence_ | uint256 | The maximum confidence |
collateralDecimals_ | uint8 | The number of decimals for the collateral |
price
Returns the price of the collateral in USDX
function price() public view override returns (uint256 assetPrice);
Returns
| Name | Type | Description |
|---|---|---|
assetPrice | uint256 | The 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
| Name | Type | Description |
|---|---|---|
collateralAmount | uint256 | The amount of collateral to calculate the cost of |
Returns
| Name | Type | Description |
|---|---|---|
totalCost | uint256 | The cost of the collateral in USDX (18 decimals) |
_collateralDecimals | uint8 | The 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
| Name | Type | Description |
|---|---|---|
age | uint256 | The age of the price |
maxAge | uint256 | The 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
| Name | Type | Description |
|---|---|---|
confidence | uint256 | The confidence of the price |
maxConfidence | uint256 | The maximum confidence |