---
description: >-
  This page describes the use cases related to investing into the TurboSwap,
  such as invest, redeem, and capital rebalance
---

# Investing

## Token Spot Price

The TurboSwap protocol acts as an automated market-maker for TurboSwap tokens.  It calculates the spot token's price$$p$$denominated in the base currency as:

$$
p = \frac{\alpha C}{N}
$$

Here$$C$$is the value of the protocol capital,$$N$$is the total number of tokens in circulation, and$$\alpha$$is the capitalization ratio, i.e. the total value of all tokens in circulation divided by the capital of the protocol:

$$
\alpha = \frac{pN}{C}
$$

This capitalization ratio could be calculated from the initial values of the capital$$C_0$$, the initial number of the tokens$$N_0$$, and the initial token price$$p_0$$:

$$
\alpha = \frac{p_0N_0}{C_0}
$$

**Example:** The reference currency is USD, the initial capital of the protocol is $6M$$(C_0 = 6,000,000)$$, the initial number of tokens is 1B$$(N_0 = 1,000,000,000)$$, and the initial token price is ¢1$$(p_0 = 0.01)$$.  Then:

$$
\alpha = \frac{p_0N_0}{C_0} = \frac{0.01 \cdot 1,000,000,000}{6,000,000} = 5/3
$$

## Token Price Invariant

If we put fees aside, then a user may invest$$\mathrm{d}C$$worth amount of assets into the capital and get$$\mathrm{d}N = \frac{\mathrm{d}C}{p}$$newly minted tokens.  Thus we have:

$$
\frac{\mathrm{d}C}{\mathrm{d}N} = p = \frac{\alpha C}{N}
$$

By solving this differential equation, we get the token price invariant:

$$
C = qN^\alpha
$$

where$$q$$is a constant quotient.  The quotient$$q$$could be calculated as:

$$
q = \frac{C}{N^\alpha}
$$

For the example above, the initial value for$$q$$would be:

$$
q = \frac{C_0}{N_0^\alpha} = \frac{6,000,000}{1,000,000,000^{5/3}} = 0.000000006
$$

so the token price invariant would be:

$$
C = 0.000000006 \cdot N^{5/3}
$$

The following graph shows the relationship between the capital$$C$$and the number of tokens in circulation$$N$$:

{% embed url="https://www.desmos.com/calculator/r76cfqzmrw" %}

And here is the relationship between the spot token price$$p$$and the number of tokens in circulation$$N$$:

{% embed url="https://www.desmos.com/calculator/kfjjqjbrm0" %}

So the spot token price goes up when the number of tokens in circulation grows.

## Invest

When a user, whose account index is$$j$$, wants to invest an$$x_i$$amount of the$$i\text{-th}$$asset into the capital, the amount is subtracted from the user's position, then a small minting fee$$\phi_m$$is charged from the amount, and the value of the remaining amount is added to the capital:

$$
\begin{array}{rcl}
v_{ij}' & = & v_{ij} - x_i \\[1em]
C' & = & C + (1 - \phi_m)p_ix_i
\end{array}
$$

Here$$p_i$$is the current price of the$$i\text{-th}$$asset denominated in the base currency.

Then, the protocol then calculates the number of new tokens$$\Delta N$$to be minted and sent to the user.  This number should preserve the token price invariant:

$$
\frac{C'}{(N + \Delta N)^\alpha} = q = \frac{C}{N^\alpha} \\[1em]
\Delta N = \left( \frac{C'}{C}N^\alpha \right)^{\frac{1}{\alpha}} - N = N \left( \frac{C'}{C} \right)^{\frac{1}{\alpha}} - N = N \left( \left( \frac{C'}{C} \right)^{\frac{1}{\alpha}} - 1\right)
$$

So, the number of token a user will get is:

$$
N \left( \left( \frac{C + (1 - \phi_m)p_ix_i}{C} \right)^{\frac{1}{\alpha}} - 1\right)
$$

## Redeem

When a user, whose account index is$$j$$, wants to redeem$$n$$for the$$i\text{-th}$$asset, first the gross payout$$x_i$$is calculated that preserves the token price invariant:

$$
\frac{C - p_ix_i}{(N - n)^\alpha} = q = \frac{C}{N^\alpha} \\[1em]
x_i = \frac{1}{p_i} \left( C - \frac{C (N - n)^\alpha}{N^\alpha} \right) = \frac{C}{p_i} \left( 1 - \left( \frac{N - n}{N} \right)^\alpha \right)
$$

A small fraction$$\phi_b$$of this gross amount is charged as a burning fee, and the remaining is added to the user's position, and redeemed tokens are burned:

$$
\begin{array}{rcl}
N' & = & N - n \\
v_{ij}' & = & v_{ij} + (1 - \phi_b) \cdot \frac{C}{p_i} \left( 1 - \left( \frac{N - n}{N} \right)^\alpha \right)
\end{array}
$$

## Capital Rebalance

The protocol capital value$$C$$is the sum of the capital values$$c_i$$for all listed assets weighted at the current asset prices$$p_i$$:

$$
C = \sum_i p_ic_i
$$

Thus the capital is exposed to market risk.  When the prices of different assets change, this affects the capital value.  Let$$\sigma_i$$be the share of the$$i\text{-th}$$asset in the capital:

$$
\sigma_i = \frac{p_ic_i}{C}
$$

Bigger$$\sigma_i$$means that the protocol capital is more exposed to the price of the $$i\text{-th}$$asset.  Note, that in some cases$$\sigma_i$$could be negative, which means, that the capital has negative (short) exposure to the price of the corresponding asset.  Anyway, the sum of$$\sigma_i$$for all the listed assets always equals to one:

$$
\sum_i \sigma_i = 1
$$

Capital allocation is a vector of all the $$\sigma_i$$values:$$\{ \sigma_i \}$$.

The governance sets a target capital allocation$$\{ \tau_i \}$$, such as:

$$
\sum_i \tau_i = 1
$$

If, for some$$i$$,$$\sigma_i < \tau_i$$, then$$i\text{-th}$$asset is underweight in the capital, i.e. the protocol needs more capital to be allocated into this asset.  If $$\sigma_i > \tau_i$$, then the asset is overweight and the protocol needs to reduce the amount of the capital allocated to this asset.

If one asset is underweight and at the same time another asset is overweight in the capital, then a capital rebalance operation is possible.

### Capital Rebalance on Exchange

Let$$i_1$$be the ID of the underweight asset and$$i_2$$be the ID of the overweight asset:

$$
\sigma_{i_1} < \tau_{i_1} \\[1em]
\sigma_{i_2} > \tau_{i_2}
$$

Let$$j$$be the ID of a user who triggers capital rebalance trade on exchange.  Let $$x_{i_1}$$ be the amount of the underweight assets for be bought for $$x_{i_2}$$units of the overweight asset.  Let $$\rho$$ be the capital rebalance reward.  Then:

$$
\begin{array}{rcl}
a_{i_1}' & = & a_{i_1} + x_{i_1} \\[1em]
a_{i_2}' & = & a_{i_2} - x_{i_2} \\[1em]
v_{i_1,j}' & = & v_{i_1,j} + \rho x_{i_1} \\[1em]
v_{i_2,j}' & = & v_{i_2,j} + \rho x_{i_2}
\end{array}
$$

It is required that$$a_{i_2} \geqslant x_{i_2}$$for the trade to be successful.  Also, the protocol checks that the under-/overweight states of the assets didn't flip after the trade, i.e. that:

$$
\sigma_{i_1}' \leqslant \tau_{i_1} \\[1em]
\sigma_{i_2}' \geqslant \tau_{i_2}
$$

### Capital Rebalance Against a User

Instead of performing capital rebalanced trade on exchange, a user may do so against the user's own account.

$$
\begin{array}{rcl}
v_{i_1,j}' & = & v_{i_i,j} - (1 - \rho)x_{i_1} \\[1em]
v_{i_2,j}' & = & v_{i_2,j} + (1 + \rho)x_{i_2}
\end{array}
$$

The trade is performed at the current price, i.e.:

$$
\frac{x_{i_1}}{x_{i_2}} = \frac{p_{i_2}}{p_{i_1}}
$$

And as usual, the protocol checks, that the under-/overweight states of the assets didn't flip and the trade didn't leave the user's account in margin call.

## Haircut

As the capital may take losses, it may go underwater, i.e. it may be that$$C < 0$$.  In such extreme conditions, the protocol is not able to repay all the deposits in full, even in case all the short positions will be covered.

During the times when the capital is underwater, the protocol operates in the underwater mode, which means:

1. Token issuance is possible at a certain minimal price, rather than at a negative price calculated by the normal price formula.
2. Token redemption is not possible.
3. Withdrawals are performed with a haircut.

The haircut withdrawal formula works like this:

$$
\begin{array}{rcl}
v_{ij}' & = & v_{ij} - x_i  \\[1em]
a_i' & = & a_i - (1 - \phi_w) x_i \frac{C^+}{-C^-}
\end{array}
$$

And a user gets just$$(1 - \phi_w) x_i \frac{C^+}{-C^-}$$units of the asset.

Here$$C^+$$is the sum of all the capital assets, i.e. reserves and short positions:

$$
C^+ = \sum_i \left( a_i - \sum_j \min \left( v_{ij}, 0 \right) \right)
$$

and$$C^+$$is the sum of all the capital obligations, i.e. long positions:

$$
C^- = \sum_i \sum_j \max \left( v_{ij}, 0 \right)
$$

Haircut encourages users to stay invested.  Also in case of unrecoverable capital damage, it allows users to return at least part of their funds.
