Introducing ADvAMM: the building block of Perpify

Perpify
8 min readJan 26, 2023

Most likely, you’re familiar with Uniswap — an automated market maker (AMM) that allows for seamless token swaps without the need for a counterparty. But have you heard of Virtual Automated Market Maker (vAMM)?

In simple terms, a vAMM is a type of AMM that utilizes a bonding curve to maintain a balance between the reserves of the two assets being exchanged, R_a and R_b. The formula for this balance is R_a*R_b=k, allowing for easy and efficient token swaps at any time.

When a user wants to swap A tokens for B tokens on vAMM, he simply sends the desired amount of A tokens to the reserve. Using the vAMM algorithm, the user will then receive the corresponding amount of B tokens, minus a small fee. The formula for this calculation is:

As you can see, the more a token is in demand, the higher its price will be.

It’s important to note that while Uniswap (and other AMMs) uses real tokens in its reserves, vAMM uses virtual tokens.

vAMMs are basically used as a price discovery tool, and vAMM-based protocols employ safekeeping accounts or vaults of stablecoins or multiple underlying assets as collateral. Additionally, specific liquidity tokens are frequently used to settle between counterparties.

The price discovery principle offered in vAMM is incredibly well suited for settling perpetual futures contracts because it automatically adjusts the prices of assets based on supply and demand in real time, which helps to ensure that prices remain fair and efficient. Additionally, there is no need for Liquidity Providers and a traditional order book.

The magic here is the price affected by each sale happening. Let’s have a look at this simple case:

  • let’s set up a virtual pool of 1.000.000 USD and 1.000.000 NFTi (means k=10¹², the price is 1 NFTi = 1 USD as the reserves are million = 10⁶ each)
  • Alice has 100 USD, uses 10x leverage, and wants to long NFTi
  • Alice uses her 100*10 = 1000 USD position and buys $10⁶-(10¹²/(10⁶+1000))=999 NFTi (let’s say the swap fee is set to 0 for simplicity)
  • the vAMM pool is now 1.001.000 USD and 999.001 NFTi, k is the same and the mark price is 1 NFTi = 1,002001 USD (grew up a bit, since there are more buys than sells)
  • Bob jumps in as well, but he wants to short with 100 USD with 15 leverage, it is 1500 USD (or “-1500” in the figure below, this minus represents his intention to sell)
  • Bob goes 999.001 - (10¹²/ (1.001.000 -1500))= -1499,25 NFTi short
  • the vAMM pool is now 999.500 USD and 1.000.500,25 NFTi, same k, and price of 1 NFTi = 0,99900025 USD (price goes down the initial level since there are more sells than buys)
  • Alice panics and cashes out to stop loss! She sells her 999 NFTi and gets 10¹² / (1.000.500,25+999) - 999.500 = 997,01 USD
  • Alice is 2,99 USD below the initial stake, it’s a loss
  • the vAMM pool is now 1.001.499,25 NFTi and 998.502,99 USD, same k, and the price of 1 NFTi = 0,9970082276 USD (goes further down, cuz everyone sells)
  • Bob cashes out and gets 10¹² / (1.001.499,25 - 1.499,25) - 998.502,99 = -1497,01$ USD position, and this is exactly 2.99 USD profit (he won because he caught the moment when the price was below his entry level)

As you can see the final state of the vAMM is equal to the initial, and total profit is equal to total loss, this is the way any vAMM works and why the concept is solvent by its’ nature.

To dive deeper — here’s the well-formulated vAMM solvency theorem you can use.

Basic vAMM is a pure “Player vs. Player” system: somebody’s winning is somebody’s losing. But actually, it’s pretty much the same when someone trades on a spot market because there’s always someone (usually a market maker) who has bought or sold you a perpetual contract. vAMM just transfers the price risks to the traders via automated price discovery.

Ok then, the main advantages of vAMM are:

  • (+) instant liquidity — even in an illiquid market
  • (+) transparent price impact & price discovery
  • (+) any asset can be traded — even with an absence of LPs for the exact pool

These are vAMM superpowers, and they are great when talking about NFT specifically because the NFT market is more separated pools and less liquid than the market of fungible tokens.

To speak about the other side of the coin let’s imagine another case (let’s say the k_fee is still set to 0 for simplicity):

  • we set up 10000 vETH and 100 vBAYC virtual pool (1 vBAYC = 100 ETH)
  • Alice has 100 ETH, uses 10x leverage, and wants to long BAYC
  • Alice uses her 100*10 = 1000 vETH and (according to the vAMM formula mentioned above) buys 9,0909 vBAYC
  • the vAMM pool is now 11000 vETH and 90,91 vBAYC, k is the same and the price of 1 vBAYC = 121 vETH
  • Bob jumps in as well, he wants to long with 200 vETH with 20x leverage, its 4000 vETH, and he buys 24,242 vBAYC
  • the vAMM pool is now 15000 vETH vs 66,67 vBAYC, same k (and crazy price of 1 vBAYC = 225 vETH)
  • Alice sees the growth and cashes out! She sells her 9,0909 vBAYC and gets 1800 vETH
  • Alice has 800 vETH profit from her initial 100 ETH stake, it’s a huge win!
  • the vAMM pool is now 13200 vETH and 75,76 vBAYC, same k, and 1 vBAYC = 174,24 vETH
  • however, if Bob cashes out he is going to be 800 vETH underwater (4x more than his initial stake was), and this is exactly what Alice won

While vAMM has its advantages, there are also some drawbacks to consider when using it:

  • (-) One issue is the accelerating price growth effect when demand is high. As seen in the example above, the change in vBAYC price for each vETH spent increases as the vBAYC price moves further away from the original price. This is due to the shape of the bonding curve and can lead to significant deviations of the vAMM price from the market price, resulting in unwanted liquidations and protocol instability.
  • (-) Another challenge is that the protocol can still incur losses despite the use of the PvP principle. As seen in the example above, Bob ended up in debt to the protocol (this is absolutely inappropriate). Additionally, there can be issues with leaks when spending protocol reserves to pay the funding rate, re-peg & k-adjustment (there gonna be examples below).

Perpify addresses the challenges of using vAMM through its advanced version, ADvAMM:

  • One solution track is the ability to change the state of the pool synchronously or asynchronously. Asynchronous regulation, also known as repeg, leads to a change in the initial price, eliminating the “sensitive” parts of the bonding curve and bringing the protocol closer to perfect equilibrium. This is achieved through a peg price function that takes into account factors such as mark vs. index price deviation, long vs. short balance and its rate of increase.
  • Another track is the use of ‘k’ adjustment (sync regulation). When large bids come in, ADvAMM automatically performs sync regulation on both sides of the pool. This allows for large bids to comfortably enter the protocol without causing significant deviations from the mark price.

It’s worth noting that both sync and async regulation can be costly as it can lead to unrealized PnL change of any opened positions, but Perpify takes this into account and regulation is only done when it is beneficial to the protocol and the reserves are sufficient.

For example, in the previous case study, if after Alice’s purchase, the protocol increased its reserves of each side of the pool by 5 times, responding to the high demand, Bob’s buy would no longer have such a large price impact because the protocol provides more liquidity.

As a result, Alice still wins, but Bob’s bid no longer goes below zero. The situation is handled correctly. You can also see the difference between Alice’s profit and Bob’s loss, which was not present in the previous examples — this is the new type of cost for the protocol, the result of sync regulation. But anyway this is a significant improvement compared to the liquidation losses in the no-balance version which could have been significantly higher for the protocol.

Other Key Features of Perpify’s ADvAMM:

  • Formulaic Swap Fees: Perpify uses variable fees for swaps, different for swap in and swap out, with values strictly limited within a reasonable range (average is 0.3%, max is 0.6%). The fee value depends on the state of the pool balance, making it easy to understand and similar to bid and ask price range depending on supply and demand.
  • Funding Payment is an effective and proven method to bring the mark price closer to the index price, creating arbitrage opportunities and market incentives for price movements in the desired direction. Perpify uses the well-known approach: (mark-index)/index together with some extra functional dependencies on the state of the pool (e.g. Longs vs Shorts balance).
  • Effective Leverage is used for liquidation, which is the ratio of the actual position state including the unrealized profit to the collateral including the same profit. Effective leverage is a sensitive and convenient way to track unhealthy positions. Perpify makes the maximum effective leverage formula-based as well, it helps to:

1) carry out partial liquidations at the most appropriate time

2) postpone liquidating a position if it is temporarily not in the Protocol’s interest to liquidate

3) max effective leverage minimum is limited of course to make the product predictable to its users, the minimum is set to 200x in the current build

  • Simple Common Sense Measures: Perpify uses separate pools for different assets, restrictions on available position size and leverage depending on the state of the pool, etc. (similar to GMX — max available liquidity approach, and important updates in Drift after the exploit).
  • Protocol-owned Liquidity (POL): this feature is worthy of its own article, but it’s important to note that it opens a whole new dimension in Perpify. LPs (liquidity providers) may not be traders, but they would be able to earn fees in this highly volatile market (note that the non-fungible perpetual futures market is potentially larger than the NFT market itself). Additionally, POL provides additional liquidity in the insurance fund, making the whole product better by providing additional confidence for traders and eliminating the need to wait for the moment when it’s possible to take a profit.

Perpify’s ADvAMM offers a unique solution to the challenges of using vAMM by implementing features such as asynchronous and synchronous regulation, formulaic swap fees, funding payments, effective leverage, and protocol-owned liquidity. These features work together to create a more stable, efficient, and user-friendly experience for traders.

But while Perpify’s approach is original, it builds on the work and ideas of other protocols such as Drift, Perp, and GMX. We would like to extend our gratitude to these protocols and wish them continued success in their growth.

--

--

Perpify

Decentralized NFT Perpetual Exchange that supports deep liquidity and low fees for leveraged trading a wide range of NFT collections.