Skip to main content

ChainlinkCalculator

A helper contract for interactions with https://docs.chain.link

Functions#

singlePrice#

function singlePrice(  contract AggregatorV3Interface oracle,  uint256 inverseAndSpread,  uint256 amount) external returns (uint256)

Calculates price of token relative to oracle unit (ETH or USD)

Parameters:#

NameTypeDescription
oraclecontract AggregatorV3Interfaceconcatenated inverse flag and spread. Lowest 254 bits specify spread amount. Spread is scaled by 1e9, i.e. 101% = 1.01e9, 99% = 0.99e9. Highest bit is set when oracle price should be inverted, e.g. for DAI-ETH oracle, inverse=false means that we request DAI price in ETH and inverse=true means that we request ETH price in DAI
inverseAndSpreaduint256
amountuint256

Return Values:#

NameTypeDescription
Amountuint256 spread oracle price

doublePrice#

function doublePrice(  contract AggregatorV3Interface oracle1,  contract AggregatorV3Interface oracle2,  uint256 spread,  int256 decimalsScale,  uint256 amount) external returns (uint256)

Calculates price of token A relative to token B. Note that order is important

Parameters:#

NameTypeDescription
oracle1contract AggregatorV3Interface
oracle2contract AggregatorV3Interface
spreaduint256
decimalsScaleint256
amountuint256

Return Values:#

NameTypeDescription
Resultuint256Token A relative price times amount