PriceOracle
Overview
License: MIT
contract PriceOracle is Initializable, AccessControlUpgradeable
Structs info
GovernedPrice
struct GovernedPrice {
uint64 timestamp;
uint256 collateralPrice;
uint256 capitalPrice;
}
PriceInfo
struct PriceInfo {
uint64 timestamp;
uint256 collateralPrice;
uint256 capitalPrice;
}
Events info
PriceUpdated
event PriceUpdated(address indexed token, uint64 currentTime, uint256 twapCollateralPrice, uint256 twapCapitalPrice)
Emitted when the price of a token is updated.
Parameters:
token
address
The address of the token.
GrantModeratorRole
event GrantModeratorRole(address indexed newModerator)
Emitted when the moderator role is granted to a new address.
Parameters:
newModerator
address
The address of the new moderator.
RevokeModeratorRole
event RevokeModeratorRole(address indexed moderator)
Emitted when the moderator role is revoked from an address.
Parameters:
moderator
address
The address of the moderator to be revoked.
SetVolatilityCapFixedPercent
event SetVolatilityCapFixedPercent(uint16 tvcUp, uint16 tvcDown)
Emitted when the new volatilityCapFixedPercent value is set.
Parameters:
tvcUp
uint16
The new tvcUp value.
tvcDown
uint16
The new tvcDown value.
SetPriceProviderAggregator
event SetPriceProviderAggregator(address newPriceProviderAggregator)
Emitted when the PriceProviderAggregator contract is set.
Parameters:
newPriceProviderAggregator
address
The address of PriceProviderAggregator contract.
Constants info
MODERATOR_ROLE (0x797669c9)
bytes32 constant MODERATOR_ROLE = keccak256("MODERATOR_ROLE")
PERCENTAGE_DECIMALS (0x90706425)
uint16 constant PERCENTAGE_DECIMALS = 10000
SECONDS_PER_HOUR (0x4df86126)
uint16 constant SECONDS_PER_HOUR = 1 hours
State variables info
priceProviderAggregator (0x407e906e)
contract IPriceProviderAggregator priceProviderAggregator
tokenPriceDecimals (0x7420b62b)
uint8 tokenPriceDecimals
tvcUp (0x465d98a3)
uint16 tvcUp
The up time-based volatility cap (TVC-up) in percentage.
tvcDown (0x8e8a4131)
uint16 tvcDown
The down time-based volatility cap (TVC-down) in percentage.
mostGovernedPrice (0x086dc126)
mapping(address => struct PriceOracle.GovernedPrice) mostGovernedPrice
Used in volatility cap rule calculations. Mapping address of token => GovernedPrice
priceInfo (0x6d048d53)
mapping(address => struct PriceOracle.PriceInfo) priceInfo
The final price after update price by calcFinalPrices function. Mapping address of token => PriceInfo.
Modifiers info
onlyAdmin
modifier onlyAdmin()
Modifier to restrict access to functions to only the contract's admin.
onlyModerator
modifier onlyModerator()
Modifier to restrict access to functions to only the contract's moderator.
Functions info
initialize (0x1c4b995a)
function initialize(
address _priceProviderAggregator,
uint16 _tvcUp,
uint16 _tvcDown
) public initializer
Initializes the contract by setting up the access control roles and assigning them to the contract deployer. The DEFAULT_ADMIN_ROLE
and MODERATOR_ROLE
roles are set up with the contract deployer as the initial role bearer. tokenPriceDecimals
is set to 10.
Parameters:
_priceProviderAggregator
address
The address of PriceProviderAggregator contract.
_tvcUp
uint16
The tvcUp value.
_tvcDown
uint16
The tvcDown value.
grantModerator (0x6981c7ae)
function grantModerator(address newModerator) external onlyAdmin
Grants the moderator role to a new address.
Parameters:
newModerator
address
The address of the new moderator.
revokeModerator (0x36445636)
function revokeModerator(address moderator) external onlyAdmin
Revokes the moderator role from an address.
Parameters:
moderator
address
The address of the moderator to be revoked.
setPriceProviderAggregator (0x5ff22c42)
function setPriceProviderAggregator(
address newPriceProviderAggregator
) external onlyModerator
Set the price provider aggregator contract address
Requirements:
The caller must be the moderator.
newPriceProviderAggregator
cannot be the zero address.
Parameters:
newPriceProviderAggregator
address
The address of the new price provider aggregator contract
setVolatilityCapFixedPercent (0x079957a9)
function setVolatilityCapFixedPercent(
uint16 _tvcUp,
uint16 _tvcDown
) external onlyModerator
Set the volatility cap fixed percent
Requirements:
The caller must be the moderator.
_volatilityCapFixedPercent
cannot be greater PERCENTAGE_DECIMALS.
Parameters:
_tvcUp
uint16
The new tvcUp value
_tvcDown
uint16
The new tvcDown value
updateFinalPrices (0x8bb6b7f9)
function updateFinalPrices(address token) external
Calculates the final TWAP prices of a token.
Parameters:
token
address
The address of the token.
getUpdatedReportedPrice (0x41f2231a)
function getUpdatedReportedPrice(
address token,
bytes32[] memory priceIds,
bytes[] memory updateData
) external payable returns (uint256)
price = priceMantissa / (10 ** priceDecimals)
returns tuple (priceMantissa, priceDecimals) after update price.
Parameters:
token
address
the address of token which price is to return
priceIds
bytes32[]
The priceIds need to update.
updateData
bytes[]
The updateData provided by PythNetwork.
getMostTWAPprice (0xbc124cfd)
function getMostTWAPprice(
address token
)
external
view
returns (
uint8 priceDecimals,
uint64 timestamp,
uint256 collateralPrice,
uint256 capitalPrice
)
Returns the most recent TWAP price of a token.
Parameters:
token
address
The address of the token.
Return values:
priceDecimals
uint8
The decimals of the price.
timestamp
uint64
The last updated timestamp of the price.
collateralPrice
uint256
The collateral price of the token.
capitalPrice
uint256
The capital price of the token.
getEstimatedTWAPprice (0x29f839b2)
function getEstimatedTWAPprice(
address token
)
public
view
returns (
uint8 priceDecimals,
uint64 timestamp,
uint256 collateralPrice,
uint256 capitalPrice
)
Returns the non-TWAP price of a token.
Parameters:
token
address
The address of the token.
Return values:
priceDecimals
uint8
The decimals of the price.
timestamp
uint64
The last updated timestamp of the price.
collateralPrice
uint256
The collateral price of the token.
capitalPrice
uint256
The capital price of the token.
getEvaluation (0x81fd01ea)
function getEvaluation(
address token,
uint256 tokenAmount
)
external
view
returns (uint256 collateralEvaluation, uint256 capitalEvaluation)
returns the most TWAP price in USD evaluation of token by its tokenAmount
Parameters:
token
address
the address of token to evaluate
tokenAmount
uint256
the amount of token to evaluate
Return values:
collateralEvaluation
uint256
the USD evaluation of token by its tokenAmount
in collateral price
capitalEvaluation
uint256
the USD evaluation of token by its tokenAmount
in capital price
getEstimatedEvaluation (0xebb19c1a)
function getEstimatedEvaluation(
address token,
uint256 tokenAmount
)
external
view
returns (uint256 collateralEvaluation, uint256 capitalEvaluation)
returns the estimated-TWAP price in USD evaluation of token by its tokenAmount
Parameters:
token
address
the address of token to evaluate
tokenAmount
uint256
the amount of token to evaluate
Return values:
collateralEvaluation
uint256
the USD evaluation of token by its tokenAmount
in collateral price
capitalEvaluation
uint256
the USD evaluation of token by its tokenAmount
in capital price
getReportedPrice (0xdbd57337)
function getReportedPrice(
address token
) public view returns (uint256 priceMantissa)
price = priceMantissa / (10 ** priceDecimals)
returns tuple (priceMantissa, priceDecimals)
Parameters:
token
address
the address of token which price is to return
Last updated