Implementation
All about our smart contracts, protocol computational accuracy, and how we determine spot prices.
Last updated
All about our smart contracts, protocol computational accuracy, and how we determine spot prices.
Last updated
The teeter Leveraged Token consists primarily of the Fund Management Contract and the Leveraged Token Contract, each of which is deployed by the Factory Contract. The Front Desk contract is responsible for the interaction between user and the teeter Protocol. For example, a Factory Contract is invoked by Front Desk contract. A Fund Management contract corresponds to a pool of leveraged tokens, which then inherits ERC20 tokens and will mint corresponding bToken. bToken represent the asset contributor's share of the pool. A Fund Management contract also corresponds to a Leveraged Token contract. The Leveraged Token Contract also inherits ERC20 tokens and will mint corresponding xTokens. The address of the Fund Management contract can be calculated, the address of the pair contract is computable.
Front Desk Contract: front-end interface, responsible for exchanging calls with the front-end factory to do various operations
Leveraged Token Contract: Leveraged Token contract, which mainly implements ERC20 functionality
Factory Contract: manages the deployment of Fund Management and Leveraged Token contracts
Fund Management Contract: position management contract, which provides for all operations of position management
The relationships between these contracts are further illustrated in the figure below:
In order to ensure computational accuracy, maintain a high transactional speed for our structed fund management model, and adapt to the requirements of the Ethereum environment, teeter uses the unsigned integer type to complete all calculations. Fractional numbers in the calculation process are processed by ascending order, which maximizes the calculation accuracy within the range of 256 bits.
teeter is handled as follows:
price = quote/base
priceEn = (quote<<112)/base
price=(priceEn>>112)
To ensure price accuracy, we raise the numerator quote by 112 places (similarly to UNISWAP) and then divide by the denominator base. The price is thus moved up 112 places, so price is expressed as priceEn in teeter. ~En indicates that the result has been bumped up 112 places. For more technical details, please see the Developer section.
Our spot prices come from two sources: firstly, from Uniswap and other DeXs (i.e., SushiSwap, PancakeSwap, dYdX, etc.) and secondly, from Chainlink Seer. When the price of an underlying asset can be obtained from multiple or all of these price channels, the spot price on teeter will be calculated by the arithmetic mean (note: not geometric mean). This will be the case for nearly all major tokens. If the underlying price is only available from one channel, however, the price for that single channel will be used. teeter will not support any tokens whose prices are not listed on any of these channel.
Why doesn't teeter use the geometric mean when calculating spot prices? By definition, underlying assets are traded on various exchanges, thus giving rise to price gaps. Once there is a large enough price gap, arbitrage opportunities will appear and arbitrageurs will be able to carry out risk-free arbitrage operations. Risk-free arbitrages will cause the price of the same underlying asset across exchanges to converge. That is, although the underlying asset trades on different exchanges, the price of the same pair of trades is normally distributed across trading venues. Therefore, a simple arithmetic average can satisfy the calculation requirements of the teeter layered fund management model while not readily giving rise to arbitrage.