Try   HackMD

V2 Vaults Calculation

f(t)= Vault.getTokenValue() at timestamp
t

t0= Timestamp at which vault was deployed or any timestamp before the first position is opened

f(t0)=1

Year= 1 Year in seconds
=31,536,000

Shares(u)= VaultToken.balanceOf(u) where u is the address of the user

PriceT(t) = Dollar value of the token
T
at timestamp
t

Vault performance

P - Vault performance between 2 timestamps
t1
and
t2

P=f(t2)f(t1)1

Vault Performance Since Inception

P - Vault performance at timestamp
t1
since inception

P=f(t1)1

Converting Vault Performance to APR & APY

Let

P be the vault performance between timestamps
t1
and
t2
and
Papr
&
Papy
be the corresponding APR & APY

N - Number of periods required to complete a year

N=Yeart2t1

Papr=PN

Papy=(1+P)N1

User Balances & Yield Earned

Let

vA(u,t) be the total of value held by the user
u
in vault
A
at timestamp
t
in the deposit token
T
, and
VA(u,t)
be its corresponding value in Dollars ($)

vA(u,t)=SharesA(u)fA(t)

VA(u,t)=vA(u,t)PriceT(t)

Let

dA(u) be the sum of all value depositted by the user
u
to the vault
A
, and
wA(u)
be the sum of all value withdrawn by the user
u
to the vault
A

Thus yield earned (in deposit token

T) by the user
u
in vault
A
is

λA(u,t)=vA(u,t)+wA(u)dA(u)

Corresponding value in dollar terms

ΛA(u,t)=λA(u,t)PriceT(t)

Following will give the total dollar value held by the user

u across all vaults

i=1nVAi(u,t)

A1 to
An
are different vaults

ROI of the User

ROI is a bit tricky to calculate

Let

t1 be the timestamp in which the user
u
first deposits to the vault
A
, and user does a deposit or withdraw events in the following timestamps
t2
,
t3
,,
tn

Let

SharesA,ta,tb(u) be the shares held by the user
u
in Vault
A
between timestamps
ta
and
tb

Given that, ROI of the user

u in vault
A
can be calculated by,

ROIA(u)=i=1n1(f(ti+1)f(ti)1)SharesA,ti,ti+1(u)i=1n1SharesA,ti,ti+1(u)

In the above equation

f(ti) is the token value of the vault
A
at timestamp
ti

Let

dA,ti(u) be the total value user holds in the vault at timestamp
ti
and no deposit/withdraw occurs till timestamp
ti+1
, then total yield earned by the user is

YieldA(u)=i=1n1(f(ti+1)f(ti)1)dA,ti(u)

Current Deposit

Use Vault.totalFunds() + Vault.totalQueuedDeposits()

Vault.totalQueuedDeposits() is invalid for Basis Trading Vault, so use Vault.totalFunds() for Basis Trading Vault

From the contracts point of view, the vaults do not have maximum capacity. Instead this will be an off-chain value and when the vaults reach this value in deposits, it'll be paused for deposits.

Vault Transactions

All vaults have events for opening a position (OpenPosition) and closing a position (ClosePosition). Read the Natspec Documentation of these events for further details.

Further, Call Selling and Put Selling vaults have two additional events. One for adding additional collateral (AddCollateral) and one for settling options (SettleOption). Again please refer to the event documentations in the contracts repo. Example - Call Selling Vault

For the logic behind clubbing the event, please co-ordinate with Gautham and Abhishek. In my opinion, every event with the same strike ID can be clubbed together for Call Selling and Put Selling. Clubbing wouldn't make much sense for Gamma Vault and Basis Trading Vault.

Vault Positions

Vault.totalFunds() is the total funds under management.

Vault.usedFunds() is the total amount of funds being used for trading, managing etc

Call Selling / Put Selling

Vault.liveStrikes() returns an array of strike IDs in which the vault have a position

Vault.positionDatas(strikeId) returns the position data of the strike ID strikeId. It returns the following data:

positionId - Corresponding Lyra Position ID
amount - Total amount of short position
collateral - Total collateral used for the position
premiumCollected - Total premium collected from this position, and this can be negative if the vault closes a position at a loss but not yet settled

Gamma Vault

Vault.positionData() returns the following data

strikeId - Current Strike ID being traded by the vault
positionId - Corresponding position ID
optionAmount - Amount of options held by the vault of strikeId
premiumPaid - Premium paid by the vault to purchase total amount of options
shortAmount - Amount of short position held by the vault in the underlying asset
totalMargin - Margin or collateral being used for holding the short position

Basis Trading

Vault.positionSize() will return the amount of short position in futures market held by the vault. Also vault will hold equal amount of underlying asset as well.

Margin will need to calculated from the Synthetix futures market contract. Will be included in the resolver.


Delta of the option with specific strikeId need to be calculated from the Lyra contracts. This will be included in the resolver.

One short position (

1e18=1) will have a delta of
1

Total delta of the Gamma Vault can be calculated by the following

αδoptionβ

where

α= optionAmount,
β=
shortAmount and
δoption=
delta of the option