# Virtual Price

## Definition

Virtual price is defined as

*virtualPrice = totalAssetBalance / totalLpSupply*

where totalAssetBalance is the summation of all balances of underlying assets and totalLpSupply is the total supply of LP tokens.

**Example A (Virtual Price Calculation):** Suppose the pool has two stablecoins USDT/USDC with balances \[1M, 1M] and the total supply of syUSD (LP token) is 1.5M, then the virtual price is (1M + 1M) / 1.5M = 1.3333.

## Virtual Price as Exchange Rate

For any pool operations that converts LP token from/to underlying asset (e.g., mint syUSD with USDT or redeem syUSD for USDC), virtual price is essential the **exchange rate** between the LP token and underlying asset **if no penalty (e.g., slippage cost) happens**.

**Example B (Redeem without Penalty)**: Suppose the pool has two stablecoins USDT/USDC with balances \[1M, 1M], total supply of syUSD (LP token) is 1.5M, and soft weights are \[0.6, 0.6].  Redeeming **0.1M** **syUSD** for USDC will not incur a penalty (as the resulting percentages are \[0.5263, 0.47368]), and as a result, the pool will return **0.13333M** **USDC** for the redemption (virtual\_price = 1.3333).

**Example C (Redeem with Penalty):**  Suppose the pool has two stablecoins USDT/USDC with balances \[1M, 1M], total supply of syUSD (LP token) is 1.5M, and soft weights are \[0.6, 0.6].  Redeeming **0.5M** syUSD for USDC will incur a penalty (as the resulting percentages will exceed 0.6), and as a result, the pool will return **less than 0.6667M USDC** for the redemption (virtual\_price = 1.3333).

One common mistake in calculating virtual price is to use the exchange rate of a transaction as virtual price, which is incorrect if such a transaction incurs a penalty.

## Virtual Price Property

One key property of virtual price is that the value should **be non-decreasing** to reflect the accumulated interest + swap fee + penalty fee, i.e., the value of per LP token is self-value-accrued over time by earning interest + swap fee + penalty fee automatically.

**Example D (Virtual Price with Fee):** Suppose the pool has two stablecoins USDT/USDC with balances \[1M, 1M], total supply of syUSD (LP token) is 1.5M. Suppose a user swaps 0.1M USDT for 0.09M USDC, the resulting pool becomes \[1.1M, 0.91M], and thus the virtual price increases from 1.3333 to 1.34.

**Example F (Virtual Price with Interest)**: Suppose the pool has two stablecoins USDT/USDC with balances \[1M, 1M], total supply of syUSD (LP token) is 1.5M. After some time, the pool earns interests \[0.1M, 0.15M] respectively.  As a result, the virtual price increases from 1.3333 to 1.5.
