-
Notifications
You must be signed in to change notification settings - Fork 31
Vault Shares Math
Vaults utilize shares to keep track of each user's pro-rata share of a vault's assets. sharess are unitless and are created/destroyed as users deposit, withdraw, pay (receive in the manager's case) fees.
| Term | Definition |
|---|---|
| Vault Equity | The current value of all vault assets in the vault's deposit asset (i.e. USDC) |
| Total Shares | A variable stored on the Vault account, the total shares created in this vault |
| User Shares | A variable stored on the Vault account, the total shares owned by VaultDepositors. |
| Vault Depositor Shares | A variable stored on each VaultDepositor account, the number of shares owned by this depositor. |
| Protocol Shares | A variable stored on the Protocol account, the total shares owned by the Protocol
|
| Manager Shares | Implied by total_shares - user_shares - protocol_shares
|
| Share Price | Implied by vault_equity / total_shares in vault's deposit asset |
For the calculations below, the following units are used:
-
shares: unitless -
amount: in the vault deposit token (i.e. USDC)
Number of shares created for the VaultDepositor when they deposit amount into the vault:
shares = amount * total_shares / vault_equity
Users must make a withdrawal request first, then wait the vault's redeem_period before they can complete their withdrawal.
At request time, we calculate withdraw_shares for the VaultDepositor in order to withdraw withdraw_amount from the vault:
withdraw_shares = withdraw_amount * total_shares / vault_equity
After redeem_period has elapsed, the user can complete their withdrawal. The amount they ultimately receive is min(amount_0, amount_1) where amount_0 is the value of their withdrawal at request time, and amount_1 is the value of their withdrawal at the time when they finally perform the withdrawal. This means the user is exposed to losses experienced during the withdrawal window, and don't enjoy any of the profits made during the withdrawal window (these are instead distributed to other users in the vault)
If the user cancels their withdrawal request while the vault was in profit, we burn some of their shares in order to forfeit any pnl they would have earned during the withdrawal window.
To calculate the shares_lost burned at cancel time (withdraw_amount and withdraw_shares are from Request time):
current_value_in_shares = withdraw_amount * (total_shares - withdraw_shares) / (vault_equity - withdraw_amount)
shares_lost = withdraw_shares - current_value_in_shares
The user simply receives the min(amount_0, amount_1), and the shares calculated during the withdraw request are subtracted from total_shares and user_shares, effectively sharing any pnl earned by the withdrawing user with remaining depositors.
Below are some examples of the shares carried out by the vault based on user interactions. The examples build on each other (i.e. user2 deposits after user1)
- user1 deposits
100_000 USDC
total depositors = 1
vault equity = 100_000 USDC
total shares = 100_000
share price = 1 USDC
user1 shares = 100_000
- user2 deposits
200_000 USDC
total depositors = 2
vault equity = 300_000 USDC
total shares = 300_000
share price = 1 USDC
user2 shares = 200_000