Timeswap AMM — A Deep Dive

Timeswap
Timeswap
Published in
7 min readNov 25, 2021

A deep dive into our 3 variable constant product AMM which enables fixed-term lending & borrowing of ERC-20 tokens with market-driven interest rate & collateral factor, all without using any oracles.

One of the most innovative solutions that have emerged during the rise of the DeFi ecosystem is the concept of the Automated Market Maker(AMM). It has now become a long-standing solution to replace the traditional order-book system of determining price and liquidity by algorithmically creating liquidity pools of tokens and enabling their trade.

In this article, we go over the concept of an AMM in general and then dive a little deeper into the Timeswap AMM and how it works.

What is an AMM?

The Automated Market Maker is an algorithm that allows digital assets to be traded in a permissionless and automated way by using liquidity pools rather than a traditional market comprised of order books. Users supply liquidity pools with tokens, whose prices are determined by a mathematical formula.

The need for an AMM in money markets

The way lending and borrowing protocols use oracles today can be compared to balancing a spherical boulder on top of a hill. It is fundamentally unstable and requires significant economic energy to counteract the economic incentives to manipulate the oracles. This is the reason why money market protocols that use oracles only have high-quality assets as collateral because they have enough economic energy for the time being to make the markets stable. This inherent problem gets exposed quickly as soon as you bring long-tail assets into the picture.

On the other hand, protocols with an oracle-less design like an AMM or an order book(which is also oracle-less) can be compared to that of having a spherical boulder in between a valley. This means that there are enough economic incentives in the market for arbitrageurs to push the boulder back to the center at the cost of the other participant whose actions led to the price dislocation from the market.

An overview of the AMM Market

Vitalik Buterin’s blog post “on-chain market makers” was the first time the idea of an AMM was proposed as a viable trading solution. His most common approach turned out to be later implemented and popularised by Uniswap with its constant product AMM(x*y=k). Different kinds of AMMs have since been implemented by protocols like Curve, Balancer, and Pendle.

Balancer’s AMM uses a constant mean formula, which allows its pools to include up to 8 tokens at any number of weights. It also permits adaptive fee structures that can react to market forces like volatility or demand. Because of this flexibility, it allows for all sorts of experimentation for projects looking to create liquidity.

Pendle introduced an AMM for its yield tokens that represent a claim on one’s future yield. The value of a yield token is time-dependent and hence, holders of a yield token are entitled to less yield with time. Their AMM solves this problem by using an AMM catering to all tokens with time-decaying properties. Initially, when the pool is created, their AMM curve is similar to Uniswap’s constant product curve. However, with subsequent swaps, their AMM curve shifts at the equilibrium point and adjusts itself to account for the time decay.

Timeswap’s native token Bond and Insurance tokens that represent the claim to yield and insurance coverage also have time decaying properties. This is an important factor to keep in mind as we dive deeper into the Timeswap AMM and find out how the time decay is taken care of.

Timeswap’s 3 Variable AMM

Timeswap works on a unique 3 variable constant product equation where interest rate & collateral factor are all market-driven and there is no dependency on oracles & liquidators.

This makes Timeswap a completely self-sufficient protocol that is permissionless & oracle-less. Anyone can create a pool with any ERC20 token as collateral & any other ERC20 token as an asset being lent/borrowed with any maturity date.

A Closer Look

Our 3 variable constant product formula is inspired by Uniswap’s Constant Product equation,

X * Y = K

Where X is the amount of the first token, Y is the amount of the second token, and K is the constant product. Inspired from Uniswap’s constant product, Timeswap employs a 3 variable constant product,

X * Y * Z = K

Timeswap’s 3 Variable Constant Product AMM

where,

X = Principal Pool is a virtual pool and is equal to the amount of assets in the pool that can be borrowed.​

Y = Interest Rate Pool is a virtual pool that determines the interest amount per second of the pool, such that ratio Y/X is the max interest rate per second of the pool.

Z = Collateral Factor Pool is a virtual pool that determines the collateral to be locked by the borrowers such that ratio Z/X is the minimum Collateralized Debt Position(CDP) of the pool.

K = Invariance Constant product

Additionally, there are two other pools :

C = Collateral Pool and is equal to the amount of ERC20 collateral tokens locked in the pool by borrowers

A = Asset Pool and is equal to the amount of ERC20 asset tokens locked in the pool. It is the sum of assets lent by lenders & the debt paid by the borrowers

Price Discovery

While interacting with the pools in this model, lenders & borrowers can change the variables X, Y, and Z such that the constant product K is always maintained. This enables real-time market price discovery of interest rate & collateral factors.

Lenders add assets to the Principal pool which increases X. To maintain the constant product, Y and Z will decrease which in turn reduces interest rates & CDP/insurance coverage for the next lender.

Lending

Borrowers withdraw assets from the Principal Pool, reducing X . To maintain the constant product Y & Z will increase thereby pushing up the interest rate and CDP.

Borrowing

Flexible Risk Profile

The AMM design provides flexibility to the end-user by allowing the users to decide their risk-return profile and accordingly set the APR for each lending or borrowing transaction.

For borrowing:

  • Lower APR will result in a higher amount of collateral locked
  • Higher APR will result in a lower amount of collateral locked

For lending:

  • Lower APR will result in a higher amount of insurance issued.
  • Higher APR will result in a lower amount of insurance issued.
Adjusting APR to manage Risk Profiles

A detailed explanation of how lending and borrowing works with the AMM can be found in our Gitbook.

Timeswap AMM and Time Decay

One major factor to consider in a constant product design is the impermanent loss in the time decaying assets/tokens caused due to the passage of time. Impermanent loss occurs when the prices of tokens inside a typical constant product AMM diverge in any direction. The greater the divergence, the greater the impermanent loss. Timeswap’s AMM, however, follows a linearly decreasing time decay to counter this problem.

Just like Pendle’s Yield Tokens, the market value of borrowers' debt & lenders' yield (calculated by variable Y) as well as borrowers' collateral to be locked & lenders' insurance coverage (calculated by variable Z) is 0 upon expiration. This would cause our liquidity providers to suffer substantial losses as Y and Z pools would be completely drained. In order to counter this, our AMM is designed to stop any IL for our LPs on their yield/insurance values caused due to the passage of time.

Y as a Time-Invariant Pool Parameter

In the calculation of debt payable by a borrower or a yield to be received by the lenders, the algorithm adjusts with time d, making Y or the Interest Rate Pool parameter as Time-Invariant.

Both Debt (D) and Yield (Yi) follow the formula Δx+ d*Δy, such that as d → 0, D = Δx, and Yi = Δx. Where Δx & Δy is the absolute change in the value of X & Y pools during lending and borrowing transactions

Y as a Time-Invariant Pool Parameter

Z as a Time-Invariant Pool Parameter

In the calculation of collateral to be locked by the borrower and the insurance value that can be claimed by a lender, the algorithm adjusts with time as d making Z or the collateral factor pool parameter as Time-Invariant.

Both Collateral to be locked (W) and Insurance to be claimed (I) follow the formula Δzmax + RΔz → Δzmax such that as d → 0, W = Δzmax & I = Δzmax. Where Δz & Δy is the absolute change in the value of X & Y pools during lending and borrowing transactions

Z as a Time-Invariant Pool Parameter

As the DeFi market expands further, we at Timeswap aim to lead the way towards DeFi 2.0 by building the most capital-efficient, secure, and permissionless money market in the web3 ecosystem.

Come aboard our Time Machine and join us in building the future of France by following us on Twitter and joining our Discord!

--

--