Haven 4.0 Slippage Development
You can download a PDF version of this blog from here.
Overview
After what seems like an eternity, Haven is finally ready to embark on a new journey in its tokenomics endeavours. Slippage.
Slippage was initially introduced as a proof of concept in our 3.1 release during the testnet phase, which was talked about here. The actual application of slippage in conversions is already built into the protocol, but it has never been enabled on the mainnet.
This is about to change.
The Economics Working Group (EWG) have worked diligently to develop a model that can safely replace VBS and allow the protocol to operate more freely, recovering without the risk of uncontrolled inflation.
The original idea behind slippage is to burn a certain amount of an asset during conversion. The amount burned would be determined by the size of a conversion between two assets and their pool ratios, where each asset’s circulating supply represents a pool. If the pool ratios are well balanced and the order size is small to moderate, slippage would be comparatively small. However, if pools are unbalanced or if the size of the conversion is large, so too would be the slippage. This is akin to using a DEX with pools to fulfil orders from buyers and sellers: the higher the order, the larger the slippage.
The EWG quickly came to realise that the initially proposed slippage would not be enough to ensure a safe transition from VBS. By utilising the State of the Protocol (its health), which is already in use with VBS, additional slippage would be applied during a bad state and gradually decreased as the state improved, allowing the protocol to recover.
Now, we will explain how slippage works and how it is going to be implemented.
What is Slippage?
Slippage represents the amount of an asset being burned during a conversion and it is calculated as a percentage. The asset to be burned is always the source asset of a conversion. If we are converting from xUSD to XHV, xUSD will be burned. If we are converting xBTC to xUSD, xBTC will be burned.
Purpose of Slippage
Slippage is intended to replace VBS, removing the restrictions of collateral and unlock times, and allowing xUSD to be re-pegged. In its first release, VBS will be reduced to a minimum, which will provide continued protection as a contingency whilst slippage is proven on the mainnet, and encourage users to buy XHV for collateral. If slippage works as intended, VBS will be removed completely in a subsequent release.
With slippage we are also going to suppress the infinite liquidity inside the vault that existed before VBS, and which is still present in conversions between xAssets (xUSD <–> xAssets).
Infinite liquidity has been one of the main reasons to an uncontrolled and unbalanced inflation in Haven’s ecosystem.
In its basic form, Slippage is used to burn part of the source asset in relation to the size of conversion. The amount burned is based on pool ratios between the two assets being converted.
Additional slippage will be applied based on the state of the protocol, defined by the market cap ratio, market price of xUSD, XHV market cap and xBTC market cap.
Slippage Prerequisites
To calculate slippage, we are going to use our existing Spot and MA prices for XHV. We are also going to create two new price feeds, xUSD Spot Price and xUSD MA (moving average).
The introduction of new price feeds means that we will have to create a new version of our oracle to incorporate these changes.
The new version will come into effect after the fork. Link to the new oracle will be shared later during the development and testing phase.
The following feeds and calculated values will be used for the slippage calculations.
xUSD market price – Spot
Part of the slippage calculation will require the spot market price of xUSD.
xUSD price feeds from our exchanges will be added to the oracle.
As with XHV price feeds, a weighted average will be calculated between all xUSD pairs, based on price and volume.
For reference and throughout this post, we are going to call this new variable XUSD_SP.
xUSD market price – Moving Average
In order to reduce manipulation of xUSD price on exchanges, we will create a 3-day moving average to track the spot price of xUSD.
We will use this to calculate certain parts of the slippage.
For reference and throughout this post, we are going to call this variable XUSD_MA.
Mcap Ratio – Spot
The market cap ratio spot calculation will be based on the XHV spot price, just like it is currently done when calculating the mcap ratio for VBS.
The formula for the spot Mcap Ratio is:
xAssetsMcap = Dollar value of the Total Offshore Assets market cap (includes xUSD, xBTC, xAU, etc.), using the notional value of $1 for xUSD.
Here, the market cap of XHV is calculated using XHV spot price.
For reference and throughout this post, we are going to call this variable MCR_SP.
Mcap Ratio – Moving Average
In order to reduce manipulation of XHV price on exchanges, we are going to use the MA price of XHV to work out the moving average of the market cap ratio.
The formula for the MA Mcap Ratio is:
xAssetsMcap = Dollar value of the Total Offshore Assets market cap (includes xUSD, xBTC, xAU, etc.), using the notional value of $1 for xUSD.
Here, the market cap of XHV is calculated using the 24hr MA price of XHV.
For reference and throughout this post, we are going to call this variable MCR_MA.
xBTC Mcap Ratio
The xBTC market cap ratio will be used to calculate the slippage for xUSD –> xBTC conversions.
The formula to calculate this ratio is:
Slippage Calculation
There are four main components in calculating the total slippage:
- Basic Slippage
Basic slippage is applied to all conversions. It is calculated by working out the pool ratios between the Source and Destination assets and applying a multiplier to these, which gives us a percentage for the slippage.
This component is conversion size dependent. The larger the conversion, the higher the slippage. - Mcap Ratio Slippage
Mcap Ratio is a measure of the state of the protocol, it’s the same ratio as the one being used for calculating the VBS, except that we are going to use two ratios, one based on the spot price of XHV (MCR-SP) and one based on the MA price of XHV (MCR-MA). This is done in order to reduce manipulation.
This component is to be applied to shoring conversions only, i.e. XHV <–> xUSD.
It is independent of the size of conversion and ensures that one cannot bypass large slippage by splitting a large conversion into smaller ones. - xUSD Peg Slippage
Additional slippage based on the market price of xUSD using the variables defined above, XUSD-SP and XUSD-MA.
This component of the slippage is to be applied to all conversions and is also independent of the size of conversion.
The more xUSD loses its peg, the higher the slippage will be, which should encourage xUSD to recover its peg if it’s too low. In combination with the 3-day MA price, it will be harder to manipulate the price of xUSD. - xBTC Mcap Ratio Slippage
The reason for this additional slippage is due to Bitcoin’s volatility and the risk of inflation to Haven’s ecosystem.
Slippage will be calculated based on the xBTC to xUSD market cap ratio. The higher the ratio, the higher the slippage.
This component is applied to xUSD –> xBTC conversions only and is conversion size independent.
In its simplest form, the Total Slippage will be calculated in the following way.
For XHV <–> xUSD conversions:
Here we are taking the maximum slippage between mcap ratio and xUSD peg, and adding it to the basic slippage.
For xUSD –> xBTC conversions:
Here we are taking the maximum slippage between xBTC and xUSD peg, and adding it to the basic slippage.
For all other xUSD <–> xAssets conversions (including xBTC –> xUSD):
We are now going to describe in detail how to calculate each of the above components.
1. Basic Slippage calculation
The Basic Slippage is directly correlated to the size of a conversion, and slippage is usually set to be higher in the Source Pool since we are taking an asset out of the pool. There is an exception for Onshores
(xUSD –> XHV), where the Destination Pool slippage can be higher. This is explained further below.
Basic Slippage is comprised of:
- Source Pool Ratio
- Source Pool multiplier
- Destination Pool Ratio
- Destination Pool multiplier
The Source Pool Ratio is multiplied by the Source Pool multiplier to give us the
Source Pool Slippage.
The Destination Pool Ratio is multiplied by the Destination Pool multiplier to give us the
Destination Pool Slippage.
We then add the two together to give us the Basic Slippage:
Source Pool Slippage
First, we need to calculate the Source Pool Ratio.
The formula for this is:
ConvertAmount is the asset amount being converted.
SourceSupply is the circulating supply of the asset being converted.
Next, we calculate the Source Pool multiplier, which is:
See table below showing how the Source Pool Multiplier changes with increasing ratio.
Finally, we calculate the Source Pool slippage, which is:
The result will give the fraction value of the percentage. This can be multiplied by 100 to give the percentage.
Source Pool Multiplier table based on the “SourcePoolMultiplier” formula described above.
Destination Pool Slippage
First, we calculate the Destination Pool Ratio.
The formula for this is:
For xUSD –> XHV conversions (onshore):
For XHV we use the minimum price between Spot and Moving Average.
For XHV –> xUSD conversions (offshore):
For XHV we use the maximum price between Spot and Moving Average.
For xUSD we use the minimum price between Spot and Moving Average.
For xAssets –> xUSD conversions:
For xUSD we use the minimum price between Spot and Moving Average.
For xUSD –> xAssets conversions:
ConvertAmount is the asset amount being converted.
AssetPrice is the price of the asset being converted. For xUSD it’s $1.
DestinationAssetMcap is the market cap of the asset being converted to.
XHVSP is the XHV spot price.
XHVMA is the XHV 24hr MA price.
Next, we calculate the Destination Pool multiplier.
For this multiplier, we are going to use a static value of 5, unless we are onshoring.
For xUSD –> XHV conversions (onshores):
This formula is highly exponential (see table below) and acts as a break if too much XHV is onshored at any time by increasing the destination pool slippage.
For all other conversions, we have:
We can now calculate the Destination Pool slippage:
The result will give the fraction value of the percentage. This can be multiplied by 100 to give the percentage.
The following table shows how the Destination Pool Multiplier changes with increasing ratio.
Applicable to onshores only (xUSD –> XHV).
Basic Slippage
The final step in calculating the Basic slippage is to add the Source and Destination slippages.
2. Mcap Ratio Slippage calculation
The Mcap Ratio slippage is to be applied to shoring conversions only, XHV <–> xUSD.
To calculate this slippage, we use the following formula:
Here we use the maximum value between the Spot and MA market cap ratio.
The higher the mcap ratio, the worse the state of the protocol and therefore the higher the slippage.
The result will give the fraction value of the percentage. This can be multiplied by 100 to give the percentage.
The following table shows how the rise in the Slippage with increasing mcap ratio.
3. xUSD Peg Slippage calculation
The xUSD peg slippage is to be applied to all conversions.
To calculate the slippage, we use the following logic and formula:
IF min(xUSD_SP, xUSD_MA) >= 1
xUSD peg slippage is set to zero if both xUSD Spot and MA are greater or equal to 1.
ELSE
The result will give the fraction value of the percentage. This can be multiplied by 100 to give the percentage.
The following table shows how the rise in the Slippage with increasing mcap ratio.
4. xBTC Mcap Ratio Slippage calculation
The xBTC slippage is to be applied to xUSD –> xBTC conversions only.
To calculate this slippage, we use the following formula:
For xUSD market cap, we use the minimum price of xUSD spot versus MA.
The following table shows how the rise in the Slippage with increasing mcap ratio.
Summary of Development
As part of the Slippage implementation, the following changes need to be made:
- Implement slippage as described above.
- Create a new oracle which will include the following:
– new price feed for xUSD spot price
– new price feed for xUSD 3 day moving average
– incorporate new price feeds for XHV from other exchanges and combine with the existing price feeds. - Change the pricing record (PR) format in the oracle to tuples, as shown in this example:
pr : {
assets : {
“XHV” { “spot”: …, “MA”: … },
“xUSD” { “spot”: …, “MA”: … }, - Reduce VBS to a fixed rate of 1 for shoring conversions (XHV <–> xUSD).
- Reduce collateral unlock time to 24 hours (720 blocks).
- Keep converted amount unlock time at 24 hours (720 blocks).
- Fees to be kept at 1.5% and to be applied to the amount being converted, before slippage is applied (this has already been implemented since Haven 3.1, but not activated).
- Remove block cap (this has already been implemented since Haven 3.1).
- Disable the following stable currencies:
XAUD, XCHF, XCNY, XGBP and XEUR
Only disable conversions going from xUSD to xCurrency, in order to allow users to exit. - Change the protocol version to 4.0 upon release.
Q & A
Question: | What happens if xUSD price feed is disrupted? |
Answer: | If there is no price feed, conversions will not be possible. Including price feeds from several exchanges will lower the risk of any disruption to the feed.. |
Question: | What happens if XHV price feed is disrupted? |
Answer: | If there is no price feed, conversions will not be possible. We are extending the price feeds of XHV in order to minimise the risk of disruption. |
Question: | Why are we disabling all the xAssets stablecoins? See Summary of Development. |
Answer: | Stable xAssets such xEUR, xCHF, etc. have not been used sufficiently enough to justify keeping them. Removing these stable xAssets will reduce the number of attack vectors and allows us to focus on our most important stablecoin: xUSD. Another reason is that converting between one stablecoin (xUSD) and another stablecoin (xEUR, etc.) makes no sense. The idea of a stablecoin in Haven’s ecosystem is to find refuge from volatile assets and/or to store a stable asset privately. Reducing the amount of unnecessary feeds in the oracle will also help reduce potential disruption in the feeds and conversions. |
Question: | What happens if the US Dollar loses its dominance or stability in the future? |
Answer: | Should anything like that happen, it will be possible to switch to another stable asset by replacing xUSD with the asset of choice. |
Question: | When will VBS be removed? |
Answer: | This depends on how Slippage performs in its first release. VBS is restrictive to our protocol, so we would like to remove it as soon as possible. Slippage will be monitored closely over the next few months. |
Appendix 1 – Conversion Examples
Here are some working examples, for each type of conversion between XHV, xUSD and xBTC.
We are going to assume the following initial values for all examples:
- XHV supply = 38,600,000
- xBTC supply = 60
- xBTC price = $70,000
- xUSD supply = 12,618,000
- Total xAssets Mcap = $17,314,000
Example 1 – xUSD to XHV
Initial values in this example:
- XHV spot price = $0.10
- XHV MA price = $0.13
- xUSD spot price = $0.30
- xUSD MA price = $0.20
- MCR-SP = 17,314,000/ (38,600,000 * 0.10) = 4.485
- MCR-MA = 17,314,000 / (38,600,000 * 0.13) = 3.450
- Amount to convert = 10,000 xUSD
Basic Slippage calculation
Source_Pool_Ratio = Convert_Amount / Source_Supply = 10,000 / 12,618,000 = 0.000793
Source_Pool_Multiplier = pow((sqrt(pow((Source_PoolRatio * 7) , 0.5)) + 1) , 5)
= pow((sqrt(pow((0.000793 * 7) , 0.5)) + 1) , 5)
= 3.342
Source_Pool_Slippage = Source_Pool_Ratio * Source_Pool_Multiplier
= 0.000793 * 3.342 = 0.00265 = 0.265%
Destination_Pool_Ratio = (Convert_Amount * Asset_Price) / Destination_Asset_Mcap
= (10,000 * $1.00) / (38,600,000 * min($0.10,$0.13)) = 0.00259
Destination_Pool_Multiplier = pow((sqrt(pow(Destination_Pool_Ratio, 0.4)) + 1), 15)
= pow((sqrt(pow(0.00259,0.4)) + 1),15) = 53.51
Destination_Pool_Slippage = Destination_Pool_Ratio * Destination_Pool_Multiplier
= 0.00259 * 53.51 = 0.1386 = 13.86%
Basic_Slippage = Source_Pool_Slippage + Destination_Pool_Slippage = 0.265% + 13.86% = 14.125%
Mcap Ratio Slippage calculation
Using the MCR_SP & MCR_MA values from above, we get:
Mcap_Ratio_Slippage = sqrt(pow(max(MCR_SP, MCR_MA), 1.2)) / 6
= sqrt(pow(max(3.450, 4.485), 1.2)) / 6
= 0.4101 = 41.01%
xUSD Peg Slippage calculation
Using the xUSD_SP & xUSD_MA values from above, we get:
xUSD_Peg_Slippage = sqrt(pow(1 – min(xUSD_SP, xUSD_MA),3)) / 1.3
= sqrt(pow(1 – min(0.30, 0.20),3)) / 1.3
= 0.5504 = 55.04%
Total Slippage
Total_Slippage = Basic_Slippage + max(Mcap_Ratio_Slippage, xUSD_Peg_Slippage)
= 14.125% + max(41.01%, 55.04%)
= 14.125% + 55.04%
= 69.165%
Example 2 – XHV to xUSD
Initial values in this example:
- XHV spot price = $3.50
- XHV MA price = $4.00
- xUSD spot price = $0.80
- xUSD MA price = $0.90
- MCR-SP = 17,314,000 / (38,600,000 * 3.50) = 0.128
- MCR-MA = 17,314,000 / (38,600,000 * 4.00) = 0.112
- Amount to convert = 10,000 XHV
Basic Slippage calculation
Source_Pool_Ratio = Convert_Amount / Source_Supply = 10,000 / 38,600,000 = 0.000259
Source_Pool_Multiplier = pow((sqrt(pow((Source_Pool_Ratio * 7) , 0.5)) + 1) , 5)
= pow((sqrt(pow((0.000259 * 7) , 0.5)) + 1) , 5)
= 2.555
Source_Pool_Slippage = Source_Pool_Ratio * Source_Pool_Multiplier
= 0.000259 * 2.555 = 0.000661745 = 0.0662%
Destination_Pool_Ratio = (Convert_Amount * Asset_Price) / Destination_Asset_Mcap
= (10,000 * max($3.50, $4.00)) / (12,618,000 * min(0.8,0.9) = 0.00396
Destination_Pool_Multiplier = 5
Destination_Pool_Slippage = Destination_Pool_Ratio * Destination_Pool_Multiplier
= 0.00396 * 5 = 0.01981 = 1.981%
Basic_Slippage = Source_Pool_Slippage + Destination_Pool_Slippage
= 0.0662% + 1.981% = 2.0472%
Mcap Ratio Slippage calculation
Using the MCR_SP & MCR_MA values from above, we get:
Mcap_Ratio_Slippage= sqrt(pow(max(MCR_SP, MCR_MA), 1.2)) / 6
= sqrt(pow(max(0.128, 0.112), 1.2)) / 6
= 0.0485 = 4.85%
xUSD Peg Slippage calculation
Using the xUSD_SP & xUSD_MA values from above, we get:
xUSD_Peg_Slippage = sqrt(pow(1 – min(xUSD_SP, xUSD_MA),3)) / 1.3
= sqrt(pow(1 – min(0.80, 0.90),3)) / 1.3
= 0.0688 = 6.88%
Total Slippage
Total_Slippage = Basic_Slippage + max(Mcap_Ratio_Slippage, xUSD_Peg_Slippage)
= 2.0472% + max(4.85%, 6.88%)
= 8.93%
Example 3 – xUSD to xBTC
Initial values in this example:
- xUSD spot price = $0.70
- xUSD MA price = $0.60
- Amount to convert = 10,000 xUSD
Basic Slippage calculation
Source_Pool_Ratio = Convert_Amount / Source_Supply = 10,000 / 12,618,000 = 0.0007925
Source_Pool_Multiplier = pow((sqrt(pow((Source_Pool_Ratio * 7) , 0.5)) + 1) , 5)
= pow((sqrt(pow((0.0007925 * 7) , 0.5)) + 1) , 5) = 3.342
Source_Pool_Slippage = Source_Pool_Ratio * Source_Pool_Multiplier
= 0.0007925 * 3.342 = 0.002648535 = 0.265%
Destination_Pool_Ratio = (Convert_Amount * Asset_Price) / Destination_Asset_Mcap
= (10,000 * $1.00) / (60 * $70,000) = 0.00238
Initial values for this example: = 5
Destination_Pool_Slippage = Destination_Pool_Ratio * Destination_Pool_Multiplier
= 0.00238 * 5 = 0.0119 = 1.19%
Basic_Slippage = Source_Pool_Slippage + Destination_Pool_Slippage
= 0.265% + 1.19%
= 1.455%
Mcap Ratio Slippage calculation
Mcap Ratio slippage only applies to shoring conversions, so:
Mcap_Ratio_Slippage = 0%
xUSD Peg Slippage calculation
Using the xUSD_SP & xUSD_MA values from above, we get:
xUSD_Peg_Slippage = sqrt(pow(1 – min(xUSD_SP, xUSD_MA),3)) / 1.3
= sqrt(pow(1 – min(0.70, 0.60),3)) / 1.3
= 0.1946 = 19.46%
xBTC Slippage calculation
xBTC_Slippage = sqrt(pow((xBTC_Mcap / (xUSD_Supply * min(xUSD_SP, xUSD_MA))), 1.4)) / 10
= sqrt(pow((4,200,000 / (12,618,000 * min(0.70, 0.60))), 1.4)) / 10
= sqrt(pow(0.55476, 1.4)) / 10 = 0.0662 = 6.62%
Total Slippage
Total_Slippage = Basic_Slippage + max(xBTC_Slippage, xUSD_Peg_Slippage)
= 1.455% + max(6.62%, 19.46%)
= 20.915%
Example 4 – xBTC to xUSD
Initial values in this example:
- xUSD spot price = $0.50
- xUSD MA price = $0.60
- Amount to convert = 0.1 xBTC
Basic Slippage calculation
Source_Pool_Ratio = Convert_Amount / Source_Supply = 0.1 / 60 = 0.00167
Source_Pool_Multiplier = pow((sqrt(pow((Source_Pool_Ratio * 7) , 0.5)) + 1) , 5)
= pow((sqrt(pow((0.00167 * 7) , 0.5)) + 1) , 5)
= 4.143
Source_Pool_Slippage = Source_Pool_Ratio * Source_Pool_Multiplier
= 0.00167 * 4.143 = 0.00691881 = 0.692%
Destination_Pool_Ratio = (Convert_Amount * Asset_Price) / Destination_Asset_Mcap
= (0.1 * $70,000) / (12,618,000 * min(0.5,0.6)) = 0.00111
Destination_Pool_Multiplier = 5
Destination_Pool_Slippage = Destination_Pool_Ratio * Destination_Pool_Multiplier
= 0.00111 * 5 = 0.00555 = 0.555%
Basic_Slippage = Source_Pool_Slippage + Destination_Pool_Slippage
= 0.692% + 0.555%
= 1.247%
Mcap Ratio Slippage calculation
Mcap Ratio slippage only applies to shoring conversions, so:
Mcap_Ratio_Slippage = 0%
xUSD Peg Slippage calculation
Using the xUSD_SP & xUSD_MA values from above, we get:
xUSD_Peg_Slippage = sqrt(pow(1 – min(xUSD_SP, xUSD_MA),3)) / 1.3
= sqrt(pow(1 – min(0.50, 0.60),3)) / 1.3
= 0.272 = 27.20%
Total Slippage
Total_Slippage = Basic_Slippage + xUSD_Peg_Slippage
= 1.247% + 27.20%
= 28.447%
Appendix 2 – Simulations
Unlike VBS, creating simulations on successive conversions is much harder with slippage because there are too many dependencies that rely on market values such as the price of XHV, xUSD and xBTC, which are impossible to predict.
The EWG have created a table of individual conversions with varying market prices for XHV and xUSD, showing the size of slippage in each case and how they are derived.
The table of simulations can be viewed using the link below, which also allows users to download and perform their own simulations.
https://cryptpad.fr/sheet/#/2/sheet/view/Omu-LMWRw0pGg05CQ91DD+b6+ohu97ytAFl74Xy5XZg/
The examples below are taken from the link shared above.