Note: Timeless AMM has been deprecated in favor of a superior solution, this paper is kept here for archival purposes.

1. Introduction

This paper will describe the derivation & details of the Timeless AMM designed for trading Timeless perpetual yield tokens (PYT) and negative yield tokens (NYT). There are three design goals of Timeless AMM:

  1. Each liquidity pool should support three tokens: the underlying asset, the PYT, and the NYT.
  2. After each trade, the price of 1 NYT and 1 PYT should always add up to 1 of the underlying asset.
  3. The yield earned by the PYTs in the liquidity pool (paid out in the underlying asset) should be automatically compounded back into the liquidity pool.

The resulting AMM is a fork of Balancer v1 that utilizes swap-based dynamic reweighting in order to satisfy the constant-price-sum invariant and implement the yield compounding.

2. The PYT invariant

We start with the Balancer constant product AMM invariant:

$$ x_0^{w_0} x_1^{w_1} x_2^{w_2} = K $$

Where $x_0$ is the reserve of the underlying asset (e.g. DAI), $x_1$ is the reserve of the negative yield token (NYT), and $x_2$ is the reserve of the perpetual yield token (PYT).

We know that the price of 1 NYT and the price of 1 PYT (in the underlying asset) should add up to 1. Therefore, we want the following invariant to hold:

$$ p_1 + p_2 = (-\frac{\partial x_0}{\partial x_1}) + (-\frac{\partial x_0}{\partial x_2}) = 1 $$

From the Balancer invariant we know

$$ x_0 = (\frac{K}{x_1^{w_1}x_2^{w_2}})^{\frac{1}{w_0}} $$

Therefore, we have

$$ \frac{\partial x_0}{\partial x_1} = -\frac{\frac{x_0}{w_0}}{\frac{x_1}{w_1}} $$

$$ \frac{\partial x_0}{\partial x_2} = -\frac{\frac{x_0}{w_0}}{\frac{x_2}{w_2}} $$

$$ \therefore p_1 + p_2 = \frac{x_0}{w_0} (\frac{w_1}{x_1} + \frac{w_2}{x_2}) = 1 $$

Thus, after each trade we must adjust $w_1, w_2$ such that the PYT invariant $\frac{x_0}{w_0} (\frac{w_1}{x_1} + \frac{w_2}{x_2}) = 1$ holds. This comes at the expense of changing the value of the Balancer invariant $K$, but that’s fine as long as we keep the relative price of the two tokens being traded the same.

3. Doing trades

A trade consists of three steps:

  • First, we accrue the yield earned by the PYTs in the pool since the last transaction (i.e. trade/add liquidity/remove liquidity) and adjust $w_0, w_1, w_2$ to keep the spot prices the same;
  • then, we do the trade using the Balancer invariant;
  • finally, we adjust $w_0, w_1, w_2$ to ensure the PYT invariant holds.

In the following analysis, we will use $\gamma$ as the fee multiplier, such that $\gamma \delta$ is used as the input amount in the Balancer invariant instead of $\delta$ (e.g. Uniswap v2 sets $\gamma = 0.997$ for example to charge a $0.3\%$ fee from trades and give it to LPs). We will also assume that the yield accrued by the PYTs in the AMM pool since the last transaction is $y$ underlying asset tokens.

Folding in accrued yield

Before each transaction, we fold the accrued yield earned by the PYTs back into the pool, while keeping all spot prices the same:

$$ p_1 = \frac{\frac{x_0}{w_0}}{\frac{x_1}{w_1}} = \frac{\frac{x_0+y}{w_0'}}{\frac{x_1}{w_1}} $$

$$ p_2 = \frac{\frac{x_0}{w_0}}{\frac{x_2}{w_2}} = \frac{\frac{x_0+y}{w_0'}}{\frac{x_2}{w_2}} $$

$$ \therefore w_0 := w_0' = \frac{x_0 + y}{x_0}w_0 $$

The symbol $:=$ is used here to denote variable assignment, so that it’s not confused with equality relations. The following sections will also use it in the same way.

Case 1: Trade between underlying asset and NYT/PYT

Let us consider a trade between the underlying asset and another token. Without loss of generality, we consider a trade between DAI and NYT.

Suppose we swap $\delta_0$ DAI for $\delta_1$ NYTs. First, we do the trade using the Balancer invariant:

$$ (x_0 + \gamma \delta_0)^{w_0}(x_1 - \delta_1)^{w_1} x_2^{w_2} = K = x_0^{w_0} x_1^{w_1} x_2^{w_2} $$

$$ \therefore \delta_1 = x_1 (1 - (\frac{x_0}{x_0 + \gamma \delta_0})^{\frac{w_0}{w_1}}) $$

Then, we want the PYT invariant to hold. If we adjusted $w_1$, the relative price between DAI and NYT will change, so we will only adjust $w_2$. Thus,

$$ \frac{x_0 + \delta_0}{w_0} (\frac{w_1}{x_1 - \delta_1} + \frac{w_2}{x_2}) = 1 $$

$$ \therefore w_2 := (\frac{w_0}{x_0 + \delta_0} - \frac{w_1}{x_1 - \delta_1})x_2 $$

Note that we cannot make the PYT invariant hold if $\delta_0$ is large enough such that $p_1$ becomes $>1$. In this case, we simply revert the transaction.

Similarly, swapping from NYTs to DAI gives:

$$ \delta_0 := x_0 (1 - (\frac{x_1}{x_1 + \gamma \delta_1})^{\frac{w_1}{w_0}}) $$

$$ w_2 := (\frac{w_0}{x_0 - \delta_0} - \frac{w_1}{x_1 + \delta_1})x_2 $$

Case 2: Trade between NYT and PYT

Suppose we swap $\delta_1$ NYTs for $\delta_2$​ PYTs. From the Balancer invariant, we have

$$ x_0^{w_0}(x_1 + \gamma \delta_1)^{w_1} (x_2 - \delta_2)^{w_2} = K = x_0^{w_0} x_1^{w_1} x_2^{w_2} $$

$$ \therefore \delta_2 = x_2 (1 - (\frac{x_1}{x_1 + \gamma \delta_1})^{\frac{w_1}{w_2}}) $$

Then, we want the PYT invariant to hold, but we also want to keep the relative price of NYTs and PYTs the same. The spot price of PYTs in NYTs is

$$ p_{12} = - \frac{\partial x_1}{\partial x_2} = \frac{\frac{x_1}{w_1}}{\frac{x_2}{w_2}} $$

Therefore, if we only adjusted $w_0$, $p_{12}$ will remain the same.

$$ \frac{x_0}{w_0}(\frac{w_1}{x_1 + \delta_1} + \frac{w_2}{x_2 - \delta_2}) = 1 $$

$$ \therefore w_0 := x_0 (\frac{w_1}{x_1 + \delta_1} + \frac{w_2}{x_2 - \delta_2}) $$

Similarly, swapping from PYTs to NYTs gives:

$$ \delta_1 = x_1 (1 - (\frac{x_2}{x_2 + \delta_2})^{\frac{w_2}{w_1}}) $$

$$ w_0 := x_0 (\frac{w_1}{x_1 - \delta_1} + \frac{w_2}{x_2 + \delta_2}) $$

4. Liquidity provision

Adding/removing liquidity using all three tokens works in the same way as Balancer, since doing so does not change the relative prices between tokens. We will thus focus on single-asset liquidity provision.

Note: Adding underlying & immediately removing PYT/NYT (and vice versa) somehow outputs more tokens than an equivalent swap. The reason is unknown. Just to be safe, Timeless only allows adding/removing single-asset liquidity using the underlying token.

4.1 Single-asset liquidity provision using the underlying asset

4.1.1 Adding liquidity

Suppose we want to add $\delta_0$ DAI into the liquidity pool. According to the Balancer white paper, the amount of pool tokens issued is:

$$ P_{issued} = P_{supply} [ ( 1 + \frac{\delta_0[1 - (1 - \gamma)(1 - \frac{w_0}{w_0 + w_1 + w_2})]}{x_0} )^{\frac{w_0}{w_0 + w_1 + w_2}} - 1 ] $$

Adding DAI into the pool without taking out NYT/PYT increases the price of both NYTs and PYTs, which clearly will violate the PYT invariant. Thus, we must modify the weights in order to maintain the PYT invariant. Because adding DAI is symmetric with regards to NYT/PYT, it doesn’t make sense for the reweighting to change the relative price between NYTs and PYTs one way or the other, therefore it must remain the same. Since

$$ p_{12} = \frac{\frac{x_1}{w_1}}{\frac{x_2}{w_2}} $$

we will update $w_0$.

From the PYT invariant, we have

$$ \frac{x_0 + \delta_0}{w_0} (\frac{w_1}{x_1} + \frac{w_2}{x_2}) = 1 $$

$$ \therefore w_0 := (x_0 + \delta_0) (\frac{w_1}{x_1} + \frac{w_2}{x_2}) $$

$$ \because \frac{x_0}{w_0} (\frac{w_1}{x_1} + \frac{w_2}{x_2}) = 1 $$

$$ \therefore \frac{w_1}{x_1} + \frac{w_2}{x_2} = \frac{w_0}{x_0} $$

$$ \therefore w_0 := \frac{x_0 + \delta_0}{x_0}w_0 $$

4.1.2 Removing liquidity

Suppose we want to remove $P_{redeemed}$ pool tokens from the liquidity pool into $\delta_0$ DAI. According to the Balancer white paper, the amount of DAI received is:

$$ \delta_0 = x_0[1 - (1 - \frac{P_{redeemed}}{P_{supply}})^{\frac{w_0 + w_1 + w_2}{w_0}}][1 - (1 - \frac{w_0}{w_0 + w_1 + w_2})(1 - \gamma)] $$

By the same logic as 3.1.1, we will update $w_0$.

From the PYT invariant, we have

$$ \frac{x_0 - \delta_0}{w_0} (\frac{w_1}{x_1} + \frac{w_2}{x_2}) = 1 $$

$$ \therefore w_0 := \frac{x_0 - \delta_0}{x_0}w_0 $$

4.2 Single-asset liquidity provision using NYT/PYT

4.2.1 Adding liquidity

Suppose we’re adding $\delta_1$ NYT to the pool. $P_{issued}$ can be computed in the same way as 3.1.1. We know that we need to update $w_1, w_2$ in order to maintain the PYT invariant, but there’s no longer symmetry between the PYT and NYT, so more complicated analysis is required.

Let $w_t = w_0 + w_1 + w_2, w_t' = w_0 + w_1' + w_2'$ be the old and new total pool weight. Let $\delta_1' = \delta_1[1 - (1 - \gamma)(1 - \frac{w_1}{w_t})]$ be the amount of NYT added to the pool minus the swap fee charged on the implicitly swapped amount. We can rewrite $P_{issued}$ as follows:

$$ P_{issued} = P_{supply} [ ( 1 + \frac{\delta_1'}{x_1} )^{\frac{w_1}{w_t}} - 1 ] $$

The first condition our updated weights $w_1', w_2'$ need to satisfy is the fairness condition, where the amount of liquidity added to the pool should be proportional to the amount of pool tokens issued to the liquidity provider, even after the reweighting. This is formalized as follows

$$ \frac{x_0^{\frac{w_0}{w_t'}} (x_1 + \delta_1')^{\frac{w_1'}{w_t'}} x_2^{\frac{w_2'}{w_t'}}}{x_0^{\frac{w_0}{w_t'}} x_1^{\frac{w_1'}{w_t'}} x_2^{\frac{w_2'}{w_t'}}} = \frac{P_{supply} + P_{issued}}{P_{supply}} $$

$$ \therefore (1 + \frac{\delta_1'}{x_1})^{\frac{w_1'}{w_t'}} = (1 + \frac{\delta_1'}{x_1})^{\frac{w_1}{w_t}} $$

$$ \therefore \frac{w_1'}{w_t'} = \frac{w_1}{w_t} $$

$$ \therefore w_1' = \frac{w_1}{w_t - w_1} (w_0 + w_2') $$

The second condition is the PYT invariant, where we can substitute $w_1'$:

$$ \frac{x_0}{w_0}(\frac{w_1'}{x_1 + \delta_1} + \frac{w_2'}{x_2}) = 1 $$

$$ \therefore \frac{x_0}{w_0}(\frac{w_1}{w_t - w_1} \frac{w_0 + w_2'}{x_1 + \delta_1} + \frac{w_2'}{x_2}) = 1 $$

$$ \therefore w_2' = w_0 \frac{\frac{x_1 + \delta_1}{x_0} - \frac{w_1}{w_t - w_1}}{\frac{w_1}{w_t - w_1} + \frac{x_1 + \delta_1}{x_2}} $$

$$ \therefore w_1' = w_0 \frac{w_1}{w_t - w_1} \frac{\frac{x_1 + \delta_1}{x_0} + \frac{x_1 + \delta_1}{x_2}}{\frac{w_1}{w_t - w_1} + \frac{x_1 + \delta_1}{x_2}} $$

4.2.2 Removing liquidity

Suppose we’re removing $\delta_1$ NYT from the pool. We can obtain the updated weights using the same reasoning as 3.2.1, except replacing $\delta_1$ with $-\delta_1$. Thus,

$$ w_1' = w_0 \frac{w_1}{w_t - w_1} \frac{\frac{x_1 - \delta_1}{x_0} - \frac{x_1 - \delta_1}{x_2}}{\frac{w_1}{w_t - w_1} + \frac{x_1 - \delta_1}{x_2}} $$

$$ w_2' = w_0 \frac{\frac{x_1 - \delta_1}{x_0} + \frac{w_1}{w_t - w_1}}{\frac{w_1}{w_t - w_1} + \frac{x_1 - \delta_1}{x_2}} $$