July 26, 2023

As part of our transition to version 2 of the Protocol, we are overhauling the swaps to make the more consistent with APY rates. In short, the variable leg for swaps based on APYs will now transition to compound interest, instead of the linear interest in version 1’ swaps.

Interest can accrue in two forms: simple and compound. Simple interest corresponds to interest paid on a constant notional, whereas compound interest will add all interest to the notional and then pay interest also on that interest. Wikipedia has a short explanation of both on its page on interest:

https://en.wikipedia.org/wiki/Interest

Variable rates used in DeFi are interest rates that accrue over the smallest unit of time in the chain, the block, which represents approx. —time. Obviously, rate exposures will generally be longer than that, so that interest will accrue consecutively, block by block at the corresponding rate. The difference between the two kinds of interest has to do with how interest is paid as the consecutive periods pass by, accruing interest one after the other.

Suppose for simplicity that the smallest accrual period is one day, so that there will be 365 periods in a year. Suppose further that the rate turns out to be a constant 1% throughout the whole month. Over the first period, a notional of 100USDC would accrue the same interest in both the simple and compound cases:

It is on the second period that the difference between both kinds of interest would show:

- simple interest would keep the nominal constant and pay again the same amount. In other words, nominal and interest are segregated for simple interest, and total interest accrued after two periods would in this example be:

- compound interest adds interest from the each period to the nominal, so in this case, the new nominal after the first period would be

The interest accrued on the second period would then be

and the interest accrued over both periods

Generally, for this example, the **simple interest** accrued on any single period would always be

so that the cumulative interest after the $n$ periods would be

On the other hand, the **compound interest** accrued on period $n$ would be

and the cumulative interest after period $n$ would come to

While the distinction between simple and compound interest is an important one in general, the question is especially pressing for DeFi products. This is because, as we mentioned, DeFi rates are always set for the smallest of time units, the block. While there are some analogies (with overnight or daily rates, instead of ‘block-y’ rates), in TradFi usually term rates for simple interest are used and quoted outside money markets - for three, six or twelve months (granted, these are small compared with the liabilities terms).

There are two acronyms that are important to keep in mind:

**APYs**(Annualized Percentage Yields) are**compounding rates**quoted as percentage points in annualized terms;**APRs**(Annualized Percentage Rate) are**simple rates**, also quoted as percentage points in annualized terms.

Typically, the borrowing protocols use APYs, for example, Aave:

Voltz’ swaps are interest rate swaps, which interchange interest rate amounts accrued over a given period - its term or maturity - , which consists of many accruing periods. Although the variable interest rates of reference are generally APYs, for v1 the choice was made to have simple interest on both legs of the swaps. Simple interest has the advantage of having a constant nominal, and so there was less of a chance to confuse users. However, this put us at odds with the compound interest consensus, and so we are now introducing swaps for which the APY rates will indeed compound. In particular, this also means that the new swaps will be perfect hedges for interest rate exposures.

Explicitly, the legs of a swap based on an APY will now be:

- a simple interest leg at a fixed rate, which is set by the vAMM at the time of the trade;
- a compound leg at the reference variable APY, accruing each block.

In particular, the nominal associated with the swap will now be the growing nominal associated with variable leg. The fixed leg does have a constant notional, but because fixed interest amounts are set in advance anyway (in the Protocol’s case, by setting a balance of fixed tokens), there is no need to remember its notional.

The easiest way to keep track of the effects of compounding is to build a compounding index: having set a base date, the liquidity index every day afterwards will be the amount that one unit of currency would have compounded since the base date - that is, the new nominal. So, following the example above, on the $n^{th}$ block after the base date, the compouding index would be

This makes it very practical to compute how the nominal grows: if we enter with nominal $N$ on period $n$, then after a subsequent period $m$ the new nominal is

Cumulative interest paid up to period $m$ is

and interest paid on period $m$ is

Understanding this last formula is a really good exercise in understanding compound interest. The product of the first two terms ($N\times I_{m-1}/I_n$) is just the nominal available at the start of period $m$; the term between parenthesis is just the interest rate for period $m$. (Check it!)

Now that we know how to update the nominal and compute compound interest amounts, the only thing to figure out is how to compute the value of a swap at some point after trade. Here’s the formula: if we enter a swap as a variable taker at block $n$ at a rate $X_n$, and a later block $m$ the market fixed rate is now $X_m$, the swap is worth

This is what is quoted as the ‘uPnL’: it is unrealized value because the Protocol does not mark the swap value to market,

Note carefully the differences with the swaps with simple interest on both legs, for which the value would just be

This has unexpected consequences: the swap will gain value even if the swap rate is constant! Be careful about what this means. Trading opportunities lurking?