Price Oracles
Overview description of how price oracles are used within the Teller protocol
Last updated
Overview description of how price oracles are used within the Teller protocol
Last updated
When making a request to the ChainLink oracle to fetch the price of a token pair, it returns a price that is scaled to a predefined number of decimals within the oracle contract. Because each token has its own number of decimals, the resulting price sometimes needs to be converted to be represented in the token that is used as collateral. The math for doing so will be outlined in the following section.
Prices in Teller are represented as 1 WHOLE lending token in collateral UNITS. Let's use an example to help clarify what's happening. Say we want the price for LINK (lending token) in USDC (collateral token).
Let:
x be the actual price in decimals of 1 LINK in USDC
where
y be the price returned from the oracle
where
R be the number of decimals within the oracle
C be the number of decimals for the collateral token
We want to take the formula for y and make it . To do this:
If C > R
the calculation is
if R > C
the calculation is
This formula is defined within the ChainlinkPairAggregator._normalizeResponse()
function here.
At present, there are some price oracles that ChainLink does not have. This means that there could be instances in which we have to get the price of 1 WHOLE collateral token in lending UNITS, and then invert the price as prices should still be represented as 1 WHOLE lending token in collateral UNITS.
This formula is defined within the InverseChainlinkPairAggregator._inverseValue()
function here.
Because the oracle returns this means .
This means 1 collateral token = lending tokens.
Therefore 1 lending token = collateral tokens.
Therefore 1 lending token = collateral units.