Skip to main content

StructPriceOracle

Git Source

Inherits: IStructPriceOracle, Ownable

Author: Struct Finance

This contract uses Chainlink's price feed to fetch the latest price of the given assets

State Variables

assetsSources

Asset -> ChainlinkSourceAddress mapping

mapping(address => AggregatorV3Interface) private assetsSources;

Functions

constructor

constructor(address[] memory assets, AggregatorV3Interface[] memory sources);

Parameters

NameTypeDescription
assetsaddress[]The addresses of the assets
sourcesAggregatorV3Interface[]The address of the Chainlink aggregator of each asset

setAssetSources

Used to set or replace sources for the assets

function setAssetSources(address[] calldata assets, AggregatorV3Interface[] calldata sources) external onlyOwner;

Parameters

NameTypeDescription
assetsaddress[]The addresses of the assets
sourcesAggregatorV3Interface[]The address of the source of each asset

_setAssetsSources

function _setAssetsSources(address[] memory assets, AggregatorV3Interface[] memory sources) internal;

getAssetPrice

Gets an asset price by address

function getAssetPrice(address asset) public view override returns (uint256);

Parameters

NameTypeDescription
assetaddressThe asset address

Returns

NameTypeDescription
<none>uint256The asset price in 18 decimals

getAssetsPrices

Gets a list of prices from a list of assets addresses

function getAssetsPrices(address[] calldata assets) external view returns (uint256[] memory);

Parameters

NameTypeDescription
assetsaddress[]The list of assets addresses

Returns

NameTypeDescription
<none>uint256[]prices The list of asset prices in 18 decimals

getSourceOfAsset

Gets the address of the source for an asset address

function getSourceOfAsset(address asset) external view returns (address);

Parameters

NameTypeDescription
assetaddressThe address of the asset

Returns

NameTypeDescription
<none>addressaddress The address of the source

Events

AssetSourceUpdated

event AssetSourceUpdated(address indexed asset, address indexed source);