In this article, we’d like to introduce you to the Virtual Automated Market Maker (vAMM) concept that powers Tsunami. Being a quite advance and recent technology in DeFi sector, it clearly requires some explanation.
An AMM is a well known concept, pioneered by Bancor and later Uninswap. It’s an exchange, that is using x * y = k formula, to algorithmically compute asset price. A concept of AMM in perfectly described by swop.fi article here.
To provide AMM with an ability to trade with leverage, and most importantly, to trade any asset, an extension to AMM protocol is required, called vAMM, or Virtual AMM. vAMM using the same x * y = k formula, except no real asset is provided to the pool (thus virtual part). Instead, a collateral (USDN) is stored in a separate vault, that allows users to buy virtual assets from AMM pools. This way, AMM is used for price discovery of a perpetual contract inside Tsunami.
Let’s follow the process step by step.
When a new vAMM contract is deployed, creator sets the initial virtual liquidity amount inside a contract, effectively controlling k.
For example, a USDN/WAVES market is being launched. Assume a contract is created with 10,000 USDN and 1,000 WAVES. Initial market price for 1 WAVES is 10 USDN. k = 10,000,000
A trader Alice wants to long waves with 3x leverage, using 100 USDN as a collateral. She deposits 100 USDN as a collateral to vault, and gets 300 USDN buying power on vAMM. Smart contract buys X Waves. X is computed using formula: (10,000 + 300) * (1,000 - x) = 10,000,000. x = 29.126 WAVES.
Contract records, that Alice have 29.126 WAVES, holds 100 USDN as collateral, and new vAMM state is 10,300 USDN and 970.874 WAVES. Market price for WAVES is now 10.60 USDN. That’s expected, since we’re buying WAVES.
Trader Bob shorts WAVES for 200 USDN with 5x leverage. He deposits 200 USDN to the same vault as Alice, and gets 1000 USDN selling power on vAMM. Smart contract sells X Waves. X is computed using formula: (10,300 - 1000) * (970.874 + x) = 10,000,000. x = 104.395 WAVES.
Contract records, that Bob have short sold 104.395 WAVES, holds 200 USDN as collateral, and new vAMM state is 9,300 USDN and 1075.269 WAVES. Market price for WAVES is now 8.648 USDN. That’s expected, since we’re selling WAVES.
You may notice, that small trades are severely affecting the price. That’s expected, because the total amount of liquidity is quite low (20,000 USDN). Such low numbers are chosen to better illustrate the principle of how virtual AMM works. Real markets well be launched with much higher liquidity amount to prevent such severe price slippage.
When using vAMM, vault will always have enough collateral to redeem each trader’s position. To prevent undercollaterized positions, a liquidation mechanism is used. It automatically closes positions, before they go bankrupt. This allows vAMM to function without liquidity providers (such as in example before, we do not need third party to provide WAVES to vAMM). Effectively, traders provide liquidity to each other.
Since every AMM (both traditional and vAMM) works as an independent market, a mechanism is needed to align AMM price to asset price in the outside world. Traditionally, an arbitrage trading is used as such a mechanism. Similar to other perpetual futures exchanges, Tsunami uses an additional mechanics called funding.
Funding incentivized arbitrageurs and traders to align perpetual future contract price with asset or index price. Funding is paid hourly, using the following formula:
In simpler words, funding works like this. Suppose vAMM price > index price. That means that we need to bring price down. This means we need more short positions. So, longs pay shorts funding, incentivizing arbitrageurs to go short to collect funding. When vAMM price < index price, it works in reverse. This way, vAMM price will closely follow index price.
As explained before, no liquidity providers are needed to run vAMM. In combination with funding payment, vAMM based exchange can track price of any asset or index. Now it’s easy to see, how Tsunami will allow trading non-crypto assets. For example, index price can be set to track the floor price of NFT collection. This allows traders to get exposure to NFT collection, while staying fully liquid - without the need to buy NFT themselves. Another example is trading real-world commodities or stock. With oracle that supplies on-chain price feed, any asset is tradable on Tsunami.
In this article, we briefly introduced the reader to how vAMM works on Tsunami Exchange. In the following articles, we will explain more on Tsunami tokenomics, perpetual futures and more. Stay tuned, and subscribe to our social media - Twitter and Telegram.