📁
Teller
  • Teller Protocol
  • Legal
    • Terms of Use
    • Privacy Policy
    • Cookie & Data Policies
  • Contracts
    • Node Network
    • Price Oracles
    • Settings.sol
    • LoansBase.sol
    • Consensus.sol
    • Gas usage
  • ATM Contracts
    • ATM Deposits & Withdrawals
  • Testing Guide
    • Getting Testnet Tokens - Rinkeby
    • Getting Testnet Tokens - Ropsten
  • Privileged Roles & Ownership
    • Overview
    • TLR Token
    • Progressive Pauser Role Ownership
  • Node & Infrastructure
    • Overview
    • Local Development
  • Platform Settings
    • Overview
Powered by GitBook
On this page
  • ChainLink
  • Price Conversion
  • Inverse Price Conversion

Was this helpful?

  1. Contracts

Price Oracles

Overview description of how price oracles are used with in the Teller protocol

PreviousNode NetworkNextSettings.sol

Last updated 4 years ago

Was this helpful?

ChainLink

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 their 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 outline in the next section.

Price Conversion

Prices in Teller are represented as 1 WHOLE lending token in collateral UNITS. Lets use an example to help clarify whats 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 x=4.14x = 4.14x=4.14

  • y be the price returned from the oracle

    • where y=x∗10Ry = x * 10 ^ {R}y=x∗10R

  • 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 y=x∗10Cy = x * 10^{C}y=x∗10C. To do this:

  • If C > R the calculation is y∗10C−Ry * 10^{C-R}y∗10C−R

  • if R > C the calculation is y/10R−Cy / 10^{R-C}y/10R−C

This formula is defined within the ChainlinkPairAggregator._normalizeResponse() function .

Inverse Price Conversion

ChainLink does not have some price oracles, which means sometimes 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.

Because the oracle returns y=x∗10Ry = x * 10 ^ {R}y=x∗10R this means x=y/10Rx = y / 10 ^ {R}x=y/10R.

This means 1 collateral token = y/10Ry / 10 ^ {R}y/10R lending tokens.

Therefore 1 lending token = 10R/y10 ^ {R} /y10R/y collateral tokens.

Therefore 1 lending token = (10R+10C)/y(10 ^ {R} + 10 ^ {C}) / y(10R+10C)/y collateral units.

This formula is defined within the InverseChainlinkPairAggregator._inverseValue() function .

here
here