# Vault Netting high level overview
starting setup
(each vault ownership of glp produces different deltas and tehy all have a vault tvl constraing)
usdc vault: GlpUsdc , TvlUsdc
ethVault:GlpEth , TvlEth
bitcoinVault:GlpBtc, TvlBtc
GlpV= GlpUsdc+GlpEth+GlpBtc
GlpM: marekt GLP ie non umami
slippage factor: 1-f(GlpV/(GlpM+GlpV)
Comp: composition of glp (ie asset percentage in glp) glpWeights*glpNotioanl + deposits from vaults (eg GlpEth adds eth to the composition)
-ie slippage is a function of share of glp
- modelling point are we doing a universally slippage (ie average over vaults) or vault specific slippage ()
Vault specific slippage
usdcVault= 1-f(Glpusdc%(GlpUsdc+GlpM))
// the hard bit is 3 different slippage to track the upside is a low tvl vault gets low slippage and better perf
Deltas (each vault produces different deltas)
GlpUSDC= short eth, short btc, short alts
GlpEth= short Btc, short alts, long eth (usdc share of glp+ notional of btc and alt hedges)
GlpBtc= short Eth, short alts, long Btc (usdc share of glp+ notional of btc and alt hedges)
Internal hedges have no slippage
external hedges have slippage wrt to vault share
so at T0 you have deposits in 3 vaults, modelling point we need to think where we net deltas the detlas are vault needs to produce also depend on inital glp composition (ie if glp is 100% eth the eth vault doesnt need to hedge )
So the deltas each vault produces for a incremental glp are
a F(Comp)- more specically current glp weights adjusted for the incremental deposit of 1 unit of the vault (ie glp weights are computed from current glp asses + 1 eth if we buy an eths worth of glp)
The bluntest approach
Adjust each vault tvl down with a leverage factor
We want a common unit ie the GLPu (the settling ccy) and to set this equal to the highest price asset in that terms (ie we dont want to buy 1btc of glp and 1usdc) we want to be the same amount and the highest value asset gives us our deposit rounding , so first we calculate our rounding so to speak
First each vault buys a unit of GLP (ie we produce GlpUsdc, GlpEth, GlpBtc)
We adjust glp total assets for the incremental deposits and then work out glp compostion we can then use this to work out the deltas each vualt produces
Then we see what nets and record this and we also recored what hasnt netted
We also need to allocate what nets to vaults (some methods, pro rata, or priority amongst vaults with lowest tvl first) and finally once we allocate to each vault we can work out for what % of netting each vault is a counterpart to the other
Then once we allocate the netted hedges to vaults for each vault we can see the remainder delta that needs to be hedged that is non netted and we allocate this
important point in the next iteration there is some slippage on the non netted hedges as there effective delta decreases from the incremental change in slippage factor
ie the effective delta is vaultSlippage* Notional so when we buy a new unit of glp next cycle you reduce yuor external hedges
We also reduce all vaults tvl wrt to what they bought GLP+ colleteral invested for each vault
So in the second iteration its the same as the above but there is a final step where you true up all your external hedges for the incremental glp purchase for each vault
you can do this till one vault runs out of tvl
then its the same but with 2 vaults, basically you do a tvl check at the start of each cycle and when a vault cant purchase it just gets zeroed
(you might want to do some clever things with the increment we buy to make this faster ie start larger and reduce etc)
(what happens with collertal do we collaterlise our own trade then we can just look at perp deltas but thats a point to sort)
A sanity check wrt to vault leverage sum of notional of glp and perp notional (ie how much mkt exposure we have) if that is higher than intial vault tvl by a some amount say 20% stop and the rest goes into buffer (ie a second lev constraint) the actualy number here needs to be backtested to prevent any liquidation issues etc etc
Now we have vaults balanced at T0 we need to think on how we can rebalance
We have a GMX oracle and each vault did netting trades and we know the decomposition of the netting too ie which vault did what, when we are done iterating we pull the latest gmx spot price for T0
Now we go to T1, we start the new cycle by pulling the GMX oracle for each spot price and computing a mark to market which gives us vault performance (we can use a common unti glpU is that the right phrase)
Some vaults will be itm on iternal hedges and some vaults out of the money
We have our % each vault is cpty to each other and combined with marks we can work out all the vault transfers
usdc-eth
usdc-btc
btc-eth
and we know which way the direction is meant to go and what we will settle with for each vault is glp + common hedges
ie if the eth vaults owes the usdc vault it can pass btc and altcoin hedge
usdc-eth (btc and alt common hedges)
usdc-btc (eth and alt common hedges)
btc-eth (alt common hedges)
in addition when we settle we also have an opportunity to open internal trades and close external
eg btc settles with eth vault and eth vault opens a eth long and the btc vault can close a market short
We can then itetate and settle the vaults for the mtm so everthing is delta neutral (ie like T0 with and calculate internal and external trades)
However at this point we dont adjust the external hedges to match we just keep a record of what we would want to be in balance
We then look for the TVL deposited in the next round which will be being added to a balanced vault and we do something analgous to step 1 ie compute internal and external netting to balance
as discussed on call you probably want to look at new deposits and also the rebalance of the strategy with the settlment and its a 2 step iteration
We now have a position snapshot of our internal hedges and how they map over vaults. We also have a snap of what we want the external hedges to be and we compare this to what they external hedges are (in aggregate and ajust)
How to distribute the fees from this adjust ( we knew what the external hedges for each vault was and we know what we want it to be now) so you can map back what each vaults delta change was
// important point GMX charges a fee to close which sucks and hopefully we can get changed... because what would be really bad is we get some flipping dynamic (ie external internal external) over cycles and keep paying fees so we need an idea of the expected gain of closing a posiiton (ie how long do our internal hedges survive in expectation) we cna look in the backtest and hopefully this is a long time
Final point all the modelling above it iterative simlar to stand alone usdc vault as figure this is easier to build given what you built in step 1 but we need to check compute time there are some things we can do to speed up or we cna look for more elegant solutions
as we get delta drift over each compute window (ie they reblance takes 10 seconds to compute but there is a gap move you get slippage) this is what it is but we need to be as latency optimised as possible
some other design thoughts as much as possible we want this to be a model that is configurable ie takes in n backing assets for index (GLP) and i vaults . Ie its easy to configure to extend to a change in GLP composition assets or if we want to role out similar products on other protocols, lets as much as possible try not to hardcode number of vaults, hardcode number of assets etc. If that makes sense?
conceptually can think of it as a index replucation problem ie index is glp and it can be i assets and n vaults where n <=i
Model Dictionary-> ie definitions for all the stuff we need to do
Model
First we need to outline all the variables (this is nice and long )
EthTvl> tvl in eth vault
UsdcTvl> tvl in uscc vault
BtcTvl > tvl in btc vault
BA=buffer adjust= x (0-1 buffer factor)
LA=leverage adjust= x (0-1 levearge factor)
Glp= mkt glp
GlpE (eth Vault glp)
GlpU (usdc vault glp)
GlpB (btc Vault glp)
GC (glp composition)
GE (eth weight in glp)> ( glpE+ethWeight*mktGlp)%(mktGlp+glpE+GlpU+GlpB)
GB (btc weight in glp)> ( glpB+btcWeight*mktGlp)%(mktGlp+glpE+GlpU+GlpB)
GS (stable weight in glp sum of usdc frax tether dai weights)>( glpS+stableWeight*mktGlp)%(mktGlp+glpE+GlpU+GlpB)
GL (Link weight in glp)> LinkWeight*Glp
GU (uni weight in glp)> uniWeight*Glp
(when we add alt vaults gl and gu becomes like GE etc ie a function of current GLP + the incremantal GLP bought by teh vault )
Composition adjust
SE=slippage factor eth vault = f(1- GlpE/(Glp+GlpE+GlpU+GlpB))
SU=slippage factor usdc vault = f(1- GlpU/(Glp+GlpE+GlpU+GlpB))
SB=slippage factor btc vault = f(1- GlpB/(Glp+GlpE+GlpU+GlpB))
Deltas (we can produce deltas and hedge with internal or a perp)
EthD
BtcD
LinkD
UniD
Perps
EthP
BtcP
LinkP
UniP
EthC> capital deployed to margin perp>EthC(btc)> capital deployed for eth hedges for the btc vault (subscript to help )
BtcC> capital deployed to margin perp
LinkC> capital deployed to margin perp
UniC> capital deployed to margin perp
Internal Hedges
EthI
BtcI
LinkI
UniI
EthIC> capital deployed to margin interals (can be 0)>EthCI(btc)> capital deployed for eth hedges for the btc vault (subscript to help )
BtcIC> capital deployed to margin interals
LinkIC> capital deployed to margin interals
UniIC> capital deployed to margin interals
vault deltas produced
glpU=UD (usdc deltas)=
btcD=-GB*GlpU
linkD=-GL*GlpU*
uniD=-GU*GlpU
ethD=- GE*GlpU
(are we doing anything with stable depeg?)
glpE=ED (eth deltas)=
btcD=-GB*GlpE
linkD=-GL*GlpE
uniD=-GU*GlpE
ethD=(GB+GL+GU+GS)*GlpE
glpB=BD (btc deltas)=
ethD=-GE*GlpB
linkD=-GL*GlpB
uniD=-GU*GlpB
btcD=(GS+GL+GU+GE)*GlpB
Constraints (what we want to solve)
TVL deployment ( we use all our tvl)
UsdcTvl*BA=EthC(Usdc)+BtcC(Usdc)+LinkC(Usdc)+UniC(Usdc)+GlpU+EthCI(Usdc)+BtcCI(Usdc)
EthTvl*BA=EthC(eth)+BtcC(eth)+LinkC(eth)+UniC(eth)+GlpU+EthCI(eth)+BtcCI(eth)
BtcTvl*BA=EthC(btc)+BtcC(btc)+LinkC(btc)+UniC(btc)+GlpU+EthCI(btc)+BtcCI(btc)
Second Leverage Constraint (face value of hedges and glp is within bounds of tvl)
UsdcTvl*(1+LA)>= EthC +BtcC+LinkC+UniC+EthI+BtcI+GlpU
EthTvl*(1+LA)>= EthC +BtcC+LinkC+UniC+EthI+BtcI+GlpE
BtcTvl*(1+LA)>= EthC +BtcC+LinkC+UniC+EthI+BtcI+GlpB
Delta Constraints (each asset)
USDC Vault
slippage adjusted hedges = glp owned by vault * asset composition factor
SU*ethC(Usdc)+SU*ethI(Usdc)= -GE*glpU =ethD(usdc)
SU*btcC(Usdc)+SU*btcI(Usdc)= -GB*glpU =btcD(usdc)
SU*LinkC(Usdc)+SU*LinkI(Usdc)= -GL*glpU =linkD(usdc)
SU*UniC(Usdc)+SU*UniI(Usdc)= -GU*glpU =uniD(usdc)
eth Vault
slippage adjusted hedges = glp owned by vault * asset composition factor
SE*ethC(Eth)+SE*ethI(Eth)= (1-GE)*glpE
SE*btcC(Eth)+SE*btcI(Eth)= -GB*glpE
SE*LinkC(Eth)+SE*LinkI(Eth)= -GL*glpE
SE*UniC(Eth)+SE*UniI(Eth)= -GU*glpE
btc Vault
slippage adjusted hedges = glp owned by vault * asset composition factor
SB*ethC(btc)+SB*ethI(btc)= -GE*glpB
SB*btcC(btc)+SB*btcI(btc)= (1-GB)*glpB
SB*LinkC(btc)+SB*LinkI(btc)= -GL*glpB
SB*UniC(btc)+SB*UniI(btc)= -GU*glpB
final constain
max glp ownership
Delta LOOP (this is just how you fit to begin or fit given you know your vault allocations doesnt handle tvl changes)
The giant loop of delta (this can almost certainly be trimmed down and optimised but im trying to seperate each conceptually step of what we are doing )
Fitting iterative
1-First we set a step size
SS=step size =
1 unit of glp will be what i use in the model below as thats simplest really we can take bigger steps . There will be some stuff below that says go back to start and reduce stepsize so we will need some logic that remember that and reduces by x and also some logic that goes step size is too small we cant reduce stop loop we are done (on infinite loops :) ) here tvl is captial free to allocate to the strategy
max(1, (min (EthTvl, btcTvl,usdcTvl))%x)) (tons of way to do this but basically im saying take bigger steps at the begining and set a min step size can be in glpU value space or usd dpeneds on waht you want to put in )
2-Get the latest vault TVL that you need to run deltas on (inclusive of new deposits or withdrawals) Increment each vaults tvl down by SS ie , here TVL is the tvl passed from the end of last loop and it iniation it tvl(0) tvl that is free to deploy leas buffer
usdcTvl(i)=usdcTvl(i-1)-SS
ethTvl(i)=ethTvl(i-1)-SS
btcTvl(i)=btcTvl(i-1)-SS
newGLP (additional glp from rebalancing) and new hedges
usdcGlp
ethGlp
btcgLp
4- buy a step size of glp for each vault
4- adjust glp compostion weights
GE (eth weight in glp)> ( glpE+ethWeight*mktGlp)%(mktGlp+glpE+GlpU+GlpB)
GB (btc weight in glp)> ( glpB+btcWeight*mktGlp)%(mktGlp+glpE+GlpU+GlpB)
GS (stable weight in glp sum of usdc frax tether dai weights)>( glpS+stableWeight*mktGlp)%(mktGlp+glpE+GlpU+GlpB)
GL (Link weight in glp)> LinkWeight*Glp
GU (uni weight in glp)> uniWeight*Glp
5- caluclate hedge ratios and vault deltas needed at this point we also add in the new glp and new hedges needed from reblaacning
vaults get handed glp and useful deltas so the extra deltas to add to calucaltion are what they dont have
we use the equations below but for rebalancing deltas we 0 the terms where we have deltas (see rebalance tracker below)
glpU=UD (usdc deltas)= -GB*GlpU -GL*GlpU -GU*GlpU - GE*GlpU
= -btcD(usdc) -linkD(usdc)-uniD(usdc)-ethD(usdc)
glpE=ED (eth deltas)= -GB*GlpE -GL*GlpE-GU*GlpE +(GB+GL+GU+GE)*GlpE
= -btcD(eth) +linkD(eth)-uniD(eth)-ethD(eth)
glpB=BD (btc deltas)= -GE*GlpB -GL*GlpB-GU*GlpB +(GU+GL+GU+GE)*GlpB
= -ethD(btc) -linkD(ntc)-uniD(Btc)-btcD(Btc)
6- (not on iniation this step is 0)
USDC Vault
ethD=GE(timeT)-GE(timeT-1)*(glpU-ss*glp) ie the glp we already purchased adjust for the change in ratios
btcD=GB(timeT)-GB(timeT-1)*(glpU-ss*glp)
linkD=GL(timeT)-GL(timeT-1)*(glpU-ss*glp)
uniD=GU(timeT)-GU(timeT-1)*(glpU-ss*glp)
eth Vault
ethD=(1-GE(timeT)-GE(timeT-1))*(glpE-ss*glp) ie the glp we already purchased adjust for the change in ratios
btcD=GB(timeT)-GB(timeT-1)*(glpE-ss*glp)
linkD=GL(timeT)-GL(timeT-1)*(glpE-ss*glp)
uniD=GU(timeT)-GU(timeT-1)*(glpE-ss*glp)
btc Vault
ethD=GE(timeT)-GE(timeT-1)*(glpB-ss*glp) ie the glp we already purchased adjust for the change in ratios
btcD=(1-GB(timeT)-GB(timeT-1))*(glpB-ss*glp)
linkD=GL(timeT)-GL(timeT-1)*(glpB-ss*glp)
uniD=GU(timeT)-GU(timeT-1)*(glpB-ss*glp)
7- add the deltas from 6 to the deltas from 5 and get full deltas
7- check what nets amongst hedges
eg for eth
nettingE= min abs (+ethI,-ethI)
nettingB=min abs (+ethB,-ethB)
8- pro rata netting to each vault based on (so when a vault runs out of tvl we cant net)
usdcBtcShare= usdcTvl% (usdcTvL+ethTvl)
ethBtcShare= ethTvl% (usdcTvL+ethTvl)
usdcEthShare= usdcTvl% (usdcTvL+BtcTvl)
btcEtcShare= ethTvl% (usdcTvL+BtcTvl)
NettingE*usdcEthShare = usdcd vault internal eth hedge= EthI(usdc)
NettingE*btcEthShare = btc vault internal eth hedge= EthI(btc)
NettingB*usdcBtcShare usdc vault internal btc hedge= EthI(usdc)
NettingB*ethBtcShare = eth vault internal btc hedge= EthI(eth)
9- subtract internal hedges from vault deltas needed
also record internal
ie usdc vault
= -btcD(usdc) -linkD(usdc)-uniD(usdc)-ethD(usdc) +ethI +btcI
10-
peprtuals to hedge balance of the detla equation and compute the cost of hedges with slippage and drain tvl by cost of hedges ie
usdcTvl= usdcTvl -1*( EthC+btcC+uniC+linkC)
ethTvl= ethTvl -1*( EthC+btcC+uniC+linkC)
btcTvl= btcTvl -1*( EthC+btcC+uniC+linkC)
We need a sanity check if tvl goes negative (then you need to go back to the start and reduce the step size) or search the other way (ie if we are over buffer we need to step the other way and reduce our open position to get beneath buffer) so you switch direction on the iteration (and reverse sign in basically everythng above)
11- second leverage check - note here the tvl is the full deposits not the tvl re incrmetnally decrease in the loop (apols i re used subscipt like a idiot) ill specify that this is tvl at i =0 ie start of fit )
UsdcTvl(i0)*(1+LA)>= EthC +BtcC+LinkC+UniC+EthI+BtcI+GlpU
EthTvl(i0)*(1+LA)>= EthC +BtcC+LinkC+UniC+EthI+BtcI+GlpE
BtcTvl(i0)*(1+LA)>= EthC +BtcC+LinkC+UniC+EthI+BtcI+GlpB
if any of these fail go back to start and reduce step size ie SS= SS%x
12-a sanity check on positive yield expectation
glp yield *t
12- We are now hedged for deltas for our new glp we have new tvl for the loop (not the leverage check) and we go back to 1 and start again
vaults fit independtly and get zeroed once tbey run out of tvl
13- this bit tells you waht we want in each vault (to be explicit we dont trade anything at this point this just tells us what we want)
14- at the end we send the output to position tracker - GLP for each vault , perps owned for each vault, internal hedges for each vault
we can also just send something like each vaults % share of each hedge and last glp composition (then you can reconstruct owernship from glp )
Rebalance Tracker - takes as input 2 sets of positions the last output from delta fit and the current output
( i think you might need a full position tracker to do fees properly as its not as simple as glp owned and weights as slippage per vault matters)- So i think for each vault position tracker takes the output of delta fit
1- Assign Fees to each vault for last epoch for funding based on perp positions (ie use t-1 ownership) and use the fee charge to top up the margin that will have been depleted from funding
- are we doing funding on internal trades?
care fees on topping
2- assign pnl to perp hedges for each vault and internal hedges (spot oracle T-T-1)
for perp pnl i think we dont need pnl we need to look at margin and top up margin from mtm of trades we want to take this from the buffer but basically
ethC(T)-ethC(T-1) is the charge each vault needs to pass back
Internal hedges
the mtm each vault needs to settle (note at this point we still dont tade anything)
each vault can pass GLP and useful hedges to settle thier balance infact what i think works best is if we pass glp and all associated hedges to the new vault
ie the btc vault passes glp eth short uni short link short and btc long to the usdc vault (the logic being we do a group delta calculation and its cheaper to change perp hedges than it is to burn glp and we dont want to deal with a vault having too much glp?)
look at difference in weights of the uncommon hedges to pass weight neutral baskets
eg weightBtc and weight eth difference
?? iterative logic like deltas to preserve max glp in settlment?
and eg if the btc vualt gets new deposits it can take back the deltas in the rebalance so we dont pay fees
3- run delta model above with the fee adjusted tvls and the rebalance changes
4- now you have the snapshot of what needs to change to be inline
Executing the delas
1- compare the asset distribution change for vaults - you dont acutally need netting hedges as by definition we are aligned for the next cycle
USDC Vault- owns glp +ethP+btcP+uniP+linkP
eth Vault- owns glp +ethP+btcP+uniP+linkP
btc Vault- owns glp +ethP+btcP+uniP+linkP
So we compare the difference in GLP sums and the difference in Perp positions
ie ethP(T)-ethP(T-1)
GLP(T)-GLP(T-1) etc
This gives what we want to adjust in terms of GLP and perps
Point on the Perp adjustment you if delta change has you reducing your perp position ie
(signum (ethP(T)-ethP(T-1))*(signum ethP(T-1))=-1
Then you can do 2 things you can either sell your perp or you could not do an internal netting trade basically if funding is low position opening/closing fees may be high so you need a constraint (v1 you just want to always blindly internally net) but we cant blindly execute
an example constraint would be closing fee>= fundingRateHourly*6hrs and discounted closing fees(this is an example we neet to think on how to fit this)
We can even do a static funding rate constraint as its a constant cost to close so could just say we only close if we expect funding costs to overwhelm closing costs after x hrs
Anyway if your constaint says dont sell then you reduce your internal hedges
ie ethI and you will keep 1 short and long position open (this gets even messier as you can track abs now you need to track longs and shorts) ill come back to this
Assume we just always interally net we now know how much more or less glp we need and how many perps we need to buy and sell
2- ingore the long cheapest to trade bit above we now know what we want to do with our execution we need some order we do this in
1- execute anything we need to sell/burn (this way we top up buffers)
2- execute everything we need to buy/mint and use deposits
3-
other thoughts
for new deposits we need a lock or fee mechanism (ie new deposits let us net but its bad if we close a bunch of positions and then people withdraw and we re open)
reduce fees on vaults you want people to enter??
scaling strategies
use treasury for weak vault
build alt vaults aswell and maybe use treasury to seed (and do options elsewhere?? is that possible)