Timeswap AMM — A Deep Dive

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 need for an AMM in money markets

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

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

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

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

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

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

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!

Like Uniswap, but for lending & borrowing