# Algorithm

## Stable Asset Architecture

Tapio Finance's backend technology consists of 2 distinct modules:

**Stable Swap Engine**Enables high-efficiency swaps between native ETH and LSTs (as well as between LSTs)

**Stable Asset Mechanism**Allows synthetic assets (tapETH) to be minted and be backed by standalone liquidity pools (i.e. stETH-ETH, lsETH-ETH, etc), as well as burning when redeemed

Maintains the composition and thereby the highly stable peg of tapETH

Both of these functions then work closely together - each LST-ETH liquidity pool serves as a trading pair between LST and native ETH which utilizes the Stable Swap Engine. This enables a dynamic trading range between ETH and the LST, but also enables the Stable Asset Mechanism to ensure that the value of the pooled assets is able to back tapETH and hence, maintain the peg.

Each LST of course represents a different form of 1 ETH within the Ethereum ecosystem, and when the exchange rate between the LST and ETH trades at 1:1, the Stable Asset mechanism will determine tapETH to be 100% collateralized and backed by ETH (whether in itβs native form, or as an LST).

When this exchange rate shifts however, tapETH becomes **overcollateralized**, with the collateral ratio increasing as the exchange rate also changes e.g. the more the LST is unpegged with ETH, the more of the tapETH composition will be native ETH, while the total supply of tapETH remains the same.

**Stable Asset Mechanism:**

**Stable Asset Mechanism:**

The most critical difference between Tapio Finance and Curve's liquidity pools is: When liquidity providers provide liquidity to the StableSwap pool, instead of getting an LP share, they receive a synthetic asset, namely a stable asset whose value is backed by the underlying StableSwap. tapETH is a synthetic stable asset that is backed by the ETH Stable Swap.

The value of the synthetic asset can be derived from the StableSwap invariant which is shown below.

In the invariant shown above,

n represents the number of underlying assets

x represents the amounts of underlying assets

A determines the "wideness" of the curve

D represents the intrinsic value of the curve

#### Parameter D

For a fixed A value, the parameter D can be seen as the total number of underlying tokens when their prices are equal. In such a case, the amount of each asset is exactly D/n. Therefore, D is the intrinsic value of the underlying StableSwap for the following reasons:

D represents the total amount of underlying assets when they are exactly pegged. They are expected to reach such an equilibrium over a long time since they are pegged to the same value;

D represents the smallest amount of assets when no underlying assets are added/removed. If any asset loses its peg, the total asset amount will exceed D since more assets are needed to keep the intrinsic value of the StableSwap;

D remains constant when underlying assets are swapped with each other.

When ETH-pegged holders provide liquidity into ETH StableSwap, the number of tapETH they receive equals the value increase of D. When they remove liquidity from ETH StableSwap, the number of tapETH burned equals the value decrease of D.

In other words, when all underlying assets are of equal prices, the stable asset is 100% collateralized and 1 tapETH is backed by exactly 1 ETH asset. When the price of any underlying asset shifts from peg, for example, when stETH loses its peg with ETH, tapETH is over-collateralized and 1 tapETH is backed by more than 1 ETH asset.

For fixed A value, the more stETH shifts away from ETH, the more ETH assets back 1 tapETH while the total supply of tapETH remains unchanged. The capability of dynamically adjusting collateral ratio is the key that tapETH maintaining its peg to ETH.

#### Parameter A

The parameter A determines the "wideness" of the curve, i.e. the curve is close to constant sum when A is big and to constant product when A is small. Therefore, parameter A can be used to adjust how fast the collateral ratio changes regarding underlying asset shifts.

When stETH peg to ETH is volatile, a smaller A is used to ensure 1 tapETH is backed by more ETH assets. tapETH's collateral ratio increases faster when stETH shifts away from its peg. When stETH's peg to ETH is stable, a larger A is used to ensure 1 tapETH is backed by fewer ETH assets. tapETH's collateral ratio increases slower when stETH shifts away from its peg. tapETH's swap liquidity and capital efficiency are also higher when A is larger.

To adjust parameter A, we observe the underlying asset proportion over a period of time.

When the underlying asset proportion is larger than 1:3 over one month, e.g. the amount of ETH is less than 25%, it's a signal that a smaller A is needed since tapETH's peg to ETH is now volatile;

When the underlying asset proportion is smaller than 1:2 over one month, e.g. the amount of ETH is more than 33%, it means stETH is relatively stable to ETH, and it's time to increase A in order to provide more swap liquidity and to enhance the capital efficiency of tapETH.

## Stable Swap Engine:

ETH Stable Swap is a backend DEX for ETH-pegged assets, including native ETH and LSTs such as stETH, cbETH, and so on, and is able to be integrated into DeFi protocols natively, using tapETH's liquidity pools to facilitate swaps. It is based on Curve's StableSwap invariant which has the following properties:

When all token prices are close, i.e. all ETH derivative assets are pegged to ETH, it's close to a constant sum curve which means 1:1 swap;

When one token price shifts away, i.e. it loses its peg with ETH, it's close to a constant product curve similar to Uniswap. The more its price shifts away, the more slippage when swapping this asset with other ETH-pegged assets.

The Stable Swap Engine provides a ETH-pegged DEX for traders. It can also help stabilize ETH-pegged assets' pegging and bootstraps the liquidity for new pegging assets.

#### To read about how our algorithm works in context of maintaining pricing stability of tapETH, check out the following pages:

Last updated