# Performance fee calculation

Fee is collected to fee_vault every time the operator sends a rebalance crank. We are currently charging 5% of profit as the performance fee. Before jumping into the formula, we define some variables:
Before rebalance:
• vault.total_amount : t1
• lp_mint.total_supply: p1
• virtual_price (value of lp token): v1 =t1/p1
After rebalance:
• vault.total_amount : t2
• lp_mint.total_supply: p1
• virtual_price: v2 =t2/p1
We charge performance fee:
$fee = 0.1* (t2-t1)$
Virtual price after fee:
$v21= (t_2-fee)/p_1$
Vault doesn't send the token directly to the treasury token account (because vault may not have enough liquidity), so vault mint more lp tokens for fee_vault. Assuming vault mints more delta lp tokens, then the new virtual price:
$v22= t2/(p1+delta)$
We still ensure the virtual price in (1) and (2) are the same v21=v22, so
$(t2-fee)/p1=t2/(p1+delta)$
Then we can calculate how many lp tokens is minted more for each rebalance crank:
$delta = (p_1*fee)/(t_2-fee)$
Or
$delta=p_1*(t_2-t_1) / (9*t_2+t_1)$