In spite of global uncertainty and volatility, it has been a very productive week for Haven’s xUSD stagenet in large part due to community participation.

A silver lining in last week’s market volatility is that we’ve had an ideal environment to test the xUSD exchange process, the Chainlink pricing oracle, xUSD exchange time locks, and the xUSD fee structure and calculation.

As a result of our testing, we’ve identified the following three issues that have now been fixed:

1) Fees for low priority xUSD exchanges were being calculated incorrectly. The low priority fee was being calculated using a 0.7% delta percentage instead of the required 0.28%. (See below for more detail on xUSD exchange fee calculations).

2) Large xUSD exchanges (generally over 10,000 XHV) were being split, resulting in some failed transactions, as a result of a broken RPC mechanism.

3) Circulating supply totals were affected by the above transaction issue.

The calculation of xUSD exchange fees, based on the variable time lock structure, is a key feature that warrants additional discussion in this post. This feature was implemented to prevent manipulation of Haven’s exchange process, particularly in times of significant market volatility, like we saw this past week.

As described in Haven’s whitepaper, the formula for calculating xUSD exchange fees uses a percentage of the delta between the XHV 12-hour moving average and the XHV spot price. You can find these quotes updated in real-time, utilizing Chainlink’s decentralized price feeds, on the Haven oracle here. “xUSD” is the spot price and “unused1” is the 12-hour MA.

The fee formula uses the following percentages for each xUSD exchange unlock priority:

High priority (60 blocks, ~2 hours): 100% of delta

Medium priority (180 blocks, ~6 hours): 63.61% of delta

Normal priority (540 blocks, ~18 hours): 16.37% of delta

Low priority (1,620 blocks, ~2 days): 0.28% of delta

The simplest way to determine the xUSD exchange fee is by using this calculation:

[Amount of XHV] x [Priority fee %] x [Delta of MA/spot] / [MA price].

An example: the 12-hour MA is $0.40 and the spot price is $0.30. The delta is $0.10. The fee for a low priority exchange of 1000 XHV would be calculated as:

[1000XHV x 0.0028 x $0.10 / $0.40] = 0.7 XHV.

That’s less than a 0.1% fee for exchanging 1000 XHV to xUSD. Fees obviously rise significantly as the delta between spot and 12 hour MA grows during volatility, and as you use a higher priority.

The delta between a $0.30 spot and $0.40 MA is significant: 33% of the spot price. A delta of this size occurred frequently during Bitcoin’s volatility last week. Right now the spread is much smaller: $0.1911 spot and $0.1880 MA: just 1.6%. This is an example of the feature working well to prevent manipulation, especially in times of significant volatility.

The testing over the past week supports the protocol design as an effective deterrent against manipulation. It would be incredibly difficult and expensive to game the xUSD exchange process, particularly in times of market volatility.

To implement the necessary changes identified in testing, we’ve restarted the stagenet from the genesis block, including the explorer and circulating supply totals. Previous stagenet wallet addresses will still work, but balances will be reset. We’d recommend creating a new wallet and starting from scratch.

Team and community members are happy to provide test funds in Discord for anyone who’d like to participate in the stagenet.

Below are links to the updated stagenet Haven Vault. Thanks to everyone for your help and contribution!

MacOS: https://github.com/haven-protocol-org/haven-web-app/releases/download/v1.2.0/Haven-macos-x64-1.2.0.zip

Windows: https://github.com/haven-protocol-org/haven-web-app/releases/download/v1.2.0/Haven-win-1.2.0.Setup.exe