๐ŸMain Concepts

The main concepts of the TurboSwap marginal trading protocol.

Accounts and Positions

Every user of the TurbosSwap protocol has an account where positions are recorded. Accounts are identified by a unique address in the blockchain where the protocol operates, i.e. Ethereum, Binance Chain, capable of running smart contracts.

For each user asset, positions are either positive (long), negative (short), or zero (void). A positive position means that the protocol owes the asset to the user. A negative position means the user owes the asset to the protocol. In other words, positive positions reflect assets deposited by the users to the protocol, while negative positions reflect assets borrowed by the users from the protocol. A position is identified by an account ID (user's address) and an asset ID.

We will use vijv_{ij} to denote the position of thej-thj\text{-th}user in the i-thi\text{-th}asset.

Reserves

The protocol itself may own assets by itself. The assets owned by the protocol are called reserves.

We will use aia_ito denote the amount of i-thi\text{-th}assets owned by the protocol.

The Capital

The capital is basically the net value of all the protocol assets. More formally it is the value of all the reserves minus the sum of all the positions. The contribution of the i-thi\text{-th}asset into the capital (denoted as cic_i) is:

ci=aiโˆ’โˆ‘jvijc_i = a_i - \sum_j v_{ij}

The capital value (denoted as CC) denominated in the base currency is:

C=โˆ‘ipiciC = \sum_i p_i c_i

Here pip_iis the current price of the i-thi\text{-th}asset denominated in the base currency.

Borrow Interest

The protocol continuously collects interest on all the negative (short) positions opened by the users. The interest is collected by increasing the absolute value of a position according to the well known compound interest formula:

vij(t)=vij(t0)โ‹…(1+ri)tโˆ’t0,ย inย caseย vij<0v_{ij} (t) = v_{ij} (t_0) \cdot (1 + r_i)^{t - t_0}\text{, in case } v_{ij} < 0

Heret0t_0is the initial time,ttis the current time, andrir_iis the borrowed interest rate for thei-thi\text{-th}asset.

Deposit Interest

The protocol charges a small fee from all the collected borrow interest, and proportionally distributes the rest among those users whose positions in the corresponding assets are positive (long). The protocol ensures that the effective deposit interest rate for an asset never exceeds the borrow rate for this asset discounted by the fee.

Consider Viโˆ’V_i^-to be the sum of all the negative (short) positions in the i-thi\text{-th}asset and Vi+V_i^+to be the sum of all the positive (long) positions in the same asset. Note, that these two values could be calculated as:

Viโˆ’=โˆ‘jvijโˆ’โˆฃvijโˆฃ2Vi+=โˆ‘jvij+โˆฃvijโˆฃ2\begin{array}{rcl} V_i^- & = & \sum_j \frac{v_{ij} - | v_{ij}|}{2} \\[1em] V_i^+ & = & \sum_j \frac{v_{ij} + | v_{ij}|}{2} \end{array}

The total interest collected during a period of time from t0t_0till t1t_1on all the negative (short) positions in i-thi\text{-th}asset is:

Viโˆ’(t0)โ‹…(1โˆ’(1+ri)t1โˆ’t0)V_i^- (t_0) \cdot \left( 1 - (1 + r_i)^{t_1 - t_0} \right)

For the effective deposit rate being equal to the borrow raterir_i, the total deposit interest (before fee) is:

Vi+(t0)โ‹…((1+ri)t1โˆ’t0โˆ’1)V_i^+ (t_0) \cdot \left( (1 + r_i)^{t_1 - t_0} - 1 \right)

So the interest amount (before fee) to be distributed among deposit holders is:

minโก(Viโˆ’(t0)โ‹…(1โˆ’(1+ri)t1โˆ’t0),Vi+(t0)โ‹…((1+ri)t1โˆ’t0โˆ’1))\min \left( V_i^- (t_0) \cdot \left( 1 - (1 + r_i)^{t_1 - t_0} \right), V_i^+ (t_0) \cdot \left( (1 + r_i)^{t_1 - t_0} - 1 \right) \right)

or, which is the same:

minโก(โˆ’Viโˆ’(t0),Vi+(t0))โ‹…((1+ri)t1โˆ’t0โˆ’1)\min \left( -V_i^- (t_0), V_i^+ (t_0) \right) \cdot \left( (1 + r_i)^{t_1 - t_0} - 1 \right)

Note, that these formulas work correctly only if the graphs ofโˆ’Viโˆ’(t)-V_i^- (t)andVi+(t)V_i^+ (t) don't cross inside the time interval fromt0t_0tot1t_1.

Ifฯ•r\phi_ris the interest rate fee, the the amount of the net interest to be distributed is:

(1โˆ’ฯ•r)โ‹…minโก(โˆ’Viโˆ’(t0),Vi+(t0))โ‹…((1+ri)t1โˆ’t0โˆ’1)(1 - \phi_r) \cdot \min \left( -V_i^- (t_0), V_i^+ (t_0) \right) \cdot \left( (1 + r_i)^{t_1 - t_0} - 1 \right)

For a positive (long) position vij>0v_{ij} > 0, the share in the collected borrow interest is:

vij(t0)Vi+(t0)โ‹…(1โˆ’ฯ•r)โ‹…minโก(โˆ’Viโˆ’(t0),Vi+(t0))โ‹…((1+ri)t1โˆ’t0โˆ’1)\frac{v_{ij} (t_0)}{V_i^+ (t_0)} \cdot (1 - \phi_r) \cdot \min \left( -V_i^- (t_0), V_i^+ (t_0) \right) \cdot \left( (1 + r_i)^{t_1 - t_0} - 1 \right)

if the graphs ofโˆ’Viโˆ’(t)-V_i^- (t)andVi+(t)V_i^+ (t) do intersect, the intersection point could be found from the following equation:

Vi+(t)+Viโˆ’(t)=0Vi+(t0)+(1โˆ’ฯ•r)โ‹…Viโˆ’(t0)โ‹…(1โˆ’(1+ri)tโˆ’t0)+Viโˆ’(t0)โ‹…(1+ri)tโˆ’t0=0Vi+(t0)+(1โˆ’ฯ•r)โ‹…Viโˆ’(t0)=(1โˆ’ฯ•r)โ‹…Viโˆ’(t0)โ‹…(1+ri)tโˆ’t0โˆ’Viโˆ’(t0)โ‹…(1+ri)tโˆ’t0Vi+(t0)+(1โˆ’ฯ•r)โ‹…Viโˆ’(t0)=โˆ’ฯ•rโ‹…Viโˆ’(t0)โ‹…(1+ri)tโˆ’t0t=t0+logโก1+riVi+(t0)+(1โˆ’ฯ•r)โ‹…Viโˆ’(t0)โˆ’ฯ•rโ‹…Viโˆ’(t0)V_i^+ (t) + V_i^- (t) = 0 \\[1em] V_i^+ (t_0) + (1 - \phi_r) \cdot V_i^- (t_0) \cdot \left( 1 - (1 + r_i)^{t - t_0} \right) + V_i^- (t_0) \cdot (1 + r_i)^{t - t_0} = 0\\[1em] V_i^+ (t_0) + (1 - \phi_r) \cdot V_i^- (t_0) = (1 - \phi_r) \cdot V_i^- (t_0) \cdot (1 + r_i)^{t - t_0} - V_i^- (t_0) \cdot (1 + r_i)^{t - t_0} \\[1em] V_i^+ (t_0) + (1 - \phi_r) \cdot V_i^- (t_0) = - \phi_r \cdot V_i^- (t_0) \cdot (1 + r_i)^{t - t_0} \\[1em] t = t_0 + \log_{1 + r_i} \frac{V_i^+ (t_0) + (1 - \phi_r) \cdot V_i^- (t_0)}{- \phi_r \cdot V_i^- (t_0)}

Effective Deposit Rate

For the i-thi\text{-th}asset, the effective deposit rateฯi\rho_i could be found from the following equation:

lnโก(1+ฯi)=1Vi+โ‹…dVi+dt\ln (1 + \rho_i) = \frac{1}{V_i^+} \cdot \frac{\mathrm{d} V_i^+}{\mathrm{d}t}

Here

dVi+dt=(1โˆ’ฯ•r)โ‹…minโก(โˆ’Viโˆ’,Vi+)โ‹…lnโก(1+ri)\frac{\mathrm{d} V_i^+}{\mathrm{d}t} = (1 - \phi_r) \cdot \min (-V_i^-, V_i^+) \cdot \ln (1 + r_i)

So,

ฯi=expโก(1Vi+โ‹…(1โˆ’ฯ•r)โ‹…minโก(โˆ’Viโˆ’,Vi+)โ‹…lnโก(1+ri))โˆ’1=(1+ri)((1โˆ’ฯ•r)minโก(โˆ’Viโˆ’,Vi+)Vi+)โˆ’1ฯi={(1+ri)((ฯ•rโˆ’1)Viโˆ’Vi+)โˆ’1,ifย ย ย Vi+>โˆ’Viโˆ’(1+ri)(1โˆ’ฯ•r)โˆ’1,otherwise\rho_i = \exp {\left( \frac{1}{V_i^+} \cdot (1 - \phi_r) \cdot \min (-V_i^-, V_i^+) \cdot \ln (1 + r_i) \right)} - 1 = (1 + r_i)^{\left( (1 - \phi_r) \frac{\min (-V_i^-, V_i^+)}{V_i^+} \right)} - 1 \\[1em] \rho_i = \begin{cases} (1 + r_i)^{\left( (\phi_r - 1) \frac{V_i^-}{V_i^+} \right)} - 1, & \text{if}\ \ \ V_i^+ > -V_i^- \\[1em] (1 + r_i)^{(1 - \phi_r)} - 1, & \text{otherwise} \end{cases}

When the total notional amount of all the long positions exceeds the total notional amount of all the short positions(Vi+>โˆ’Viโˆ’)(V_i^+ > -V_i^-), then the effective deposit rate depends on the borrow interest raterir_i, the interest rate feeฯ•r\phi_r, and the short-to-long ratio Viโˆ’Vi+\frac{V_i^-}{V_i^+}. Otherwise, it depends only on the deposit rate and the fee.

Last updated