BlockPo / BlockPo-to-Tradelayer

Incubation Repo for the TradeLayer protocol, 0.2.0
http://www.tradelayer.org
Other
8 stars 8 forks source link

Mark Price Calculation Component 3: Weighting Formula #482

Open patrickdugan opened 2 years ago

patrickdugan commented 2 years ago

This a simple function that builds off the RPC look-up tools of the previous two tickets and applies some simple math:

Define the N block filter for our anti-wash trading filtration = RoundDown(WeighedAvg(Volatility_Samples)%0.005+1)

The Weighed Average would weigh the most recent volatility as 50% of the average to be more sensitive to attack shocks.

The default would filter out WT block-to-block as long as the volatility is very low (<0.5%), and quickly increase it to several blocks. This would quickly limit the ability of a holder of e.g 10,000 ALL and -20,000 ALL/LTC contracts from shocking the mark price in an attempted liquidation raid. In combination with per-block limit breakers of 5%, this would give room to orderly liquidate some and allow other liquidity to come in and try to arb it with the high rebates. A full-on attack could only move the price the 5%, and then have to wait 10 blocks to continue the attack, then shocking the price lower, wait 14 or 15 blocks and so on. It gets even better though.

Mark Price is weighted from 3 VWAPs:

a) the filtered vwap of ALL/LTC trade channel spot trades b) the vwap of ALL/sLTC on-chain trades c) the vwap of LTC/sLTC trade channel trades

If LTC/sLTC is trading at 0.8, like a UST style shock depegging attack, instead of adjusting ALL/sLTC up 20%, it would be weighted e.g. 25% by default and only 5% adjusted. So if ALL/LTC is trading at 0.04 suddenly, and ALL/sLTC is trading at 0.05 still, and LTC/sLTC is trading at 0.8, the market is pricing in the 20% but the Mark price will read 0.0525 at a 25% of 20% weighting upward and 0.04 at half weight averages to 0.048333_.

By default when the volatility filter variable above, N, is 1, the weightings would be 25%, 50%, 25%. When volatility spikes the formula will shift. At N=2, the 25% weightings would drop to 12.5% and the ALL/sLTC orderbook takes 75% share. At N=3, the 12.5% drops to 8.333% and the ALL/sLTC orderbook takes about 83.333% share and so on.

So the result should be that the distortion in sLTC and the weight of wicks from trade channels will be reduced and an attacker must go through the stacks of orders standing on the orderbook to arb down. This means the trade channels need real counterparties to make it profitable to pay those rebates to those ALL/sLTC bidders.

We can also possible increase the rebate dramatically in this period and have the taker fees go up. It's like how perpetual swaps reward longs but treating the liquidity in sLTC in a similar way.

We should test this with bots on testnet that try to attack the native ecosytem with liquidation raids, and we'll see how we do.