Understand hAMM and Position Mining of Derify

Derivation Lab
8 min readMay 13, 2021

Hedged Automated Market Making, or hAMM, is the liquidity solution of Derify protocol, today’s blog we will break down the basics and introduce this hybrid mechanism with characteristics of order-book model of traditional CEX or AMM model of Uniswap.

Let’s start with the basics: Your Account Balance.

Blockchain is a digital database of transactions. When you trade on Derify, your account data and account balance will be stored on a blockchain. Due to the high gas fee and slow speed of Ethereum Mainnet, clearing and calculation for all trading activities will happen on one of the Ethereum side chains as short-term alternatives. For Derify, we are deployed on BNB Chain, which means your account data, account balance and trading data will all be stored on BNB Chain, no matter how our interface looks like.

Derify is multi chain compatible, you can use BNB Chain, Matic, ETH and other supported network to access the infinite liquidity on Derify. And we are deploying our on several alternative chains that allows fast and cheap Contract Calculation, including BNB, Matic, Arbitrum.

Derify is using Cross Margin Account mode, which means all your positions shares a same balance pool as that can be used as margins. Some of your positions may have unrealized profit and some may have unrealized loss. They will be calculated together. When the net unrealized loss exceeds the balance pool, the whole balance pool will be liquidated.

Besides Cross Margin model, some exchanges on the market have Isolated Margin mode, which means each position has its own balance pool that tied with the position that can be used as margins, if one of your position’s unrealized loss exceeds this isolated balance pool, only the balance pool tied with that position will be liquidated. However, we do not provide Isolated Margin mode on Derify, since experienced traders can achieve same result by smart combination of stop-limit orders.

Second, what happens when we Open Positions?

In traditional order book model, you make/take an order, the system will match you with another order, thus create/close a position. if no suitable order is found, your order remains in the order book until you cancel it.

In hAMM model, however, you don’t need to match with other orders. You make indication about your desired starting price, margin, leverage and direction of the asset price, then you can instantly have your position in place, a clearing keeper program will calculate your opening price, margin, and remaining equity on retrospective fashion, to ensure you always get the price on the moment when you open the position, rather than the moment the position is shown as confirmed.

Derify put all positions together in a “Position Pool” for calculation.

Example

When oracles tell all traders, the price of BTC is 60000 USDT at this moment:

Apple believes the price will rise, so Apple open a 1 BTC long position on Derify, then indicate the leverage is 2x, the position is 60000 USDT, margin is 30000 USDT. The position will be opened shortly after he made indication, at the price of this moment.

Baker believes the price will fall, so Baker open a 1 BTC short position on Derify, then indicate the leverage is 2x, the position is 60000 USDT, margin is 30000 USDT. The position will be opened shortly after he made indication, at the price of this moment.

Both position of Apple and Baker will be put into the position pool.

2. Open Position

Third, what happens when we Close Positions?

In typical AMM model, you swap an asset for another asset according to the algorithm, after the swap, the pool for different asset changes, then price/swap rate will adjust accordingly.

In hAMM model, however, we don’t have any price discovery mechanism, you also don’t swap with any pools or asset. All prices are from oracles and your trading will have no influence on the price, you simply get the same AMM experience of instant pricing.

You make indication about your desired closing price, margin, leverage, the clearing keeper program will close the position when the desired closing price is reached, also calculate your closing price, remaining equity and your realized profit/loss. After the trade, the price of oracles remains unchanged, and oracles will continue to feed multiple prices to the system regardless of your trading activities.

Both positions closed by Apple and Baker will also be calculated into the position pool.

For all positions in the Position Pool, some of the positions end up in profit, some others end up in loss, all the profit/loss of positions will be calculated together, as the profit/loss of the Position Pool.

Example

When oracles tell all traders, the price of BTC is 70000 USDT at this moment:

Apple holds a long position on Derify, leverage is 2x, the position is 60000 USDT, the margin is 30000 USDT. Apple decides to close the position now, the system will first calculate that Apple end up winning 10000 USDT, thus the remaining equity withdrawable is 40000 USDT. After closing, the position pool has 60000 USDT of long positions less.

Baker holds a short position on Derify, leverage is 2x, the position is 60000 USDT, initial margin is 30000 USDT. Baker decides to close the position now, the system will first calculate that Baker end up losing 10000 USDT, thus the remaining equity withdrawable is 20000 USDT. After closing, the position pool has 60000 USDT of short positions less.

After the calculation, we find the Apple and Baker’s trading activities does not change anything in the Position Pool, but Apple end up winning the same amount that Baker is losing.

3. Close Position

Fourth, what is the relationship between liquidity and positions?

As we discussed above, the short position (Baker’s) pays out the profit of the long position (Apple’s). In any similar events, long and short positions will pay off each other, which is essentially the liquidity we need to sustain further payment to trading activities. i.e. Position is liquidity.

Imagine if Apple is closing the position with unrealized profit of 10000 USDT, but Baker’s position does not exist, then no one is paying the profit to Apple, and the trading activities will not be sustained — there’s shortage of liquidity.

In these scenarios, despite seemingly infinite liquidity in your trading experience, Derify may also have liquidity problem just like any other exchange. i.e. No position means no liquidity.

Therefore, we need people who hold positions to provide liquidity to the opposite positions, the more positions you held, the more liquidity you provide for opposite positions.

4. Position is liquidity

Fifth, how Derify encourages people to provide liquidity.

As we discussed above, hAMM rely on infinite liquidity, thus Derify encourages liquidity provider or “liquidity miners” to provide extra liquidity to the exchange.

Because holding positions means providing liquidity for Derify, therefore unlike typical liquidity mining programs, Derify do not have a separate “liquidity pool” for miners to stake assets and create liquidity. Since Derify calculates all liquidity within the Position Pool, and all positions creates liquidity, Derify have Position Mining mechanism to directly reward all positions held, regardless of their direction, amount, and people holding the position.

By rewarding all positions held with yield, traders are also miners in Derify, that creates multiple advantages: first, liquidity miners provide liquidity with leverage and also farm with leverage, increase both money efficiency and return on investments; second, traders now directly benefit from their daily trading activities; third, it’s much easier for everyone to participate in liquidity mining, rather than splitting their money into different pools that cost gas fees.

On the other hand, because there’s always somewhat an imbalance of positions pool, which means the liquidity of long and short positions are not equal, and If there’s lots of long positions and little short positions, the liquidity risk exposure of Derify will be very big. Thus, Derify also has Dynamic Adjustment to mining rewards: if there’s more long positions than short positions in the position pool, long position holders will receive less yield than short position holders.

In general, to receive mining rewards, you only need to open positions, and hold them.

5. Position Mining

Sixth, how to provide liquidity with no risk.

Many traders or miners who wants to receive mining rewards are worry about two risks: the liquidation risk and profit/loss risk.

Liquidation risk means your position for mining may be liquidated, thus you cannot participate the Position Mining anymore; Profit/Loss risk means your position for mining may be in profit/loss, that you may want to realize your profit/loss at some point, so you need to re-open other positions to receive yields.

Derify offers special two-way positions for Position Mining. Traders can open both long position and short position with the same price, same leverage, same amount, at same time, but in different directions.

Because Derify is using the cross margin model, so the unrealized profit/loss of the two positions will be calculated together. So when the price of an asset rises, your long position may be in net profit, but your short position may be in net loss of the same amount, and vice versa. No matter how the price fluctuates, the two positions will zero out each other, so your total unrealized profit/loss is always zero, which means your two-way positions will never be liquidated and be in loss.

Because holding positions will receive rewards, both long and short part of your two-way positions will earn yields for you.

6. Risk Free Position Mining

Hopefully this article helps you understand how Derify’s market making system works and how liquidity is provided.

We wish you a good mining experience on Derify.

Please spread the words, for the future of DeFi community.

Follow/Subscribe us for more updates!

--

--