🐇Deep Dive
Swap
We use a modified version of the uniswap V2 constant product AMM algo for market making:
xy = kv, where v is the virtual liquidity factor.
We modified the algo to include virtual liquidity so that the liquidity is spread across a dynamic range (depending on the actual liquidity added) rather than being spread across 0 to infinity.
A simple example:
Let the initial price of the DC/DAWG be set at 100 & let the virtual liquidity factor be 2.
The pool contains 10 DC NFTs & 1000 $DAWG tokens.
Virtual liquidity pool now contains 20 NFTs & 2000 $DAWG tokens
Swaps in both the directions collects 0.5% fee in $DAWG out of which 0.4% is distributed between the liquidity providers depending on their share in the pool , remaining 0.1% is collected by protocol as platform fee.
DogeSwap is designed in such a way that the fee collected & distributed to the LPs can be set for each NFT / token pair supported by DogeSwap.
Swap from DC NFT to $DAWG:
=> 21*(2000-y) = 20*2000 => y = 2000 - (20*2000)/21 = 95.238 $DAWG
User pays , 1 DC NFT
User receives, 95.238 - (0.5% of 95.238) = 94.76 $DAWG
LP’s Receives = (0.5% of 95.238) = 0.476 $DAWG
Protocol Receives = (0.1% of 95.238) = 0.095 $DAWG
Swap from $DAWG to DC NFT:
=> 19*(2000+y) = 20*2000 => y = (20*2000)/19 - 2000 = 105.263 $DAWG
User pays, 105.263 + (0.5% of 105.263) = 105.789 $DAWG
User receives, 1 DC NFT
LP’s Receives = (0.5% of 105.263) = 0.476 $DAWG
Protocol Receives = (0.1% of 105.263) = 0.095 $DAWG
Liquidity
Swap efficiency
DogeSwap AMM leverages virtual liquidity to provide better capital efficiency & lower price impact per trades compared to traditional AMMs. Each pool has a virtual liquidity factor that is used to calculate the additional virtual liquidity that will be deployed by the AMM.
Let the initial price of the DC/DAWG be set at 100 & let the virtual liquidity factor be 2.
User “A” adds 10 NFTs & 1000 tokens to the pool. Since the virtual liquidity (v = 2) , virtual AMM pool will now contain a total of 20 NFTs & 2000 tokens out of this only 10 NFTs & 1000 tokens is the real liquidity.
Normal AMM:
If the user “A” adds 10 NFTs & 1000 tokens to the pool. Total number of NFTs and tokens in the pool will be 10 & 1000 respectively & liquidity is spread across [0,infinity] range.
If a user wants to sell 1 NFT , user would receive (y) 11*(1000-y)=10000 y = 90.909 $DAWG
If a user wants to buy 1 NFT , user would have to pay (y) 9*(1000+y)=20000 y = 111.11 $DAWG
DogeSwap AMM:
If user “A” adds 10 NFTs & 1000 tokens to the pool. Since the virtual liquidity (v = 2) , virtual AMM pool will now contain a total of 20 NFTs & 2000 tokens out of this only 10 NFTs & 1000 tokens is the real liquidity.
If a user wants to sell 1 NFT , user would receive (y) 21*(2000-y)=40000 y = 95.238 $DAWG
If a user wants to buy 1 NFT , user would have to pay (y) 19*(2000+y)=40000 y = 105.263 $DAWG
Unlike normal AMM DogeSwap AMM does not provide liquidity in the [0,infinity] range . Let’s calculate the range of DogeSwap AMM when liquidity provided is 10 NFTs , 1000 tokens & vliquidity factor is 2.
If a user wants to buy 9 NFTs , user would have to pay (y) 11*(2000+y)=40000 y = 1636.363 $DAWG
If a user wants to buy 10 NFTs , user would have to pay (y) 10*(2000+y)=40000 y = 2000 $DAWG
Since there are actually only 10 NFTs in the pool , price difference between 1st & 10th NFT buy would be the range of the AMM. Price of 10th NFT = 2000 - 1636.363 = 363.637 Price increase in % vs 1st buy = (363.637)*100/105.263 = 345.45 %
So the range of the AMM in the conditions above would be [initial price/3.45, initial price*3.45].
So the price of an NFT can swing 3.45 times to both sides and DogeSwap AMM would still be operational. DogeSwap AMM also allows LPs to adjust the vliquidity factor thereby adjusting the range of the AMM.
Removing Liquidity
Removing liquidity is a bit tricky since we deal with both NFTs & tokens in our AMM rather than just the fungible tokens.
Example
Let there be 3 users, User A, User B & User C.
User A deposits 1 NFT & 100 token
User B deposits 2 NFT & 200 tokens
Pool state: pooledNFTs = 3 pooledTokens = 300 virtualNFTs = 4 virtualTokens = 600
Now user A owns ⅓ of the pool & User B owns ⅔ of the pool.
User C swapped a Doge to DAWG
User C receives 5*(600-y) = 2400 y = 120 $DAWG
Pool state: pooledNFTs = 5 pooledTokens = 180 virtualNFTs = 5 virtualTokens = 480
User A & B still owns ⅓ & ⅔ of the pool respectively.
User A NFT Balance = ⅓ * 5 = 1.667 Token Balance = ⅓ * 180 = 60 User B NFT Balance = ⅔ * 5 = 3.33 Token Balance = ⅔ * 180 = 120
Now suppose User A wants to withdraw his liquidity, the protocol owes him 1.667 NFTs and 60 tokens but since NFTs can only be whole numbers we use our DogeSwap AMM to swap 0.667 NFTs to token at the current swap price, since NFT is being sold it will decrease the price of NFT in the pool. Once the internal swap is complete the protocol then distributes 1 NFT , 60 tokens & the equivalent of 0.667 NFTs in tokens to the user.
If no swap happens after the two users add liquidity then removing liquidity won't affect the price of the NFT since the NFT share of both users would be whole numbers and therefore no internal swap is required.
Potential Arbitrage Scenarios
The DogeSwap arbitrage engine uses Raydium & Elixir to perform arbitrages, for now.
Lets 1 NFT costs $100 , 1 token costs $1 , and the price of 1 NFT in the DogeSwap pool is 100 tokens.
Right now the three markets are in equilibrium with each other. The equilibrium gets disturbed when the price in any one of these markets change.
Suppose the price of NFT increased to $150, the arbitrage route would be
1. User buys 100 tokens from raydium (total cost : $100) 2. User swaps 100 tokens to NFT in dogeswap 3. User sells the NFT in the marketplace for $150
Profit = $150 - $100 = $50
Suppose the price of token increased to $1.5, the arbitrage route would be
1. User buys an NFT from the marketplace for $100 2. User swaps NFT to tokens in dogeswap (user receives 100 tokens) 3. User sells 100 tokens in raydium for $150
Profit = $150 - $100 = $50
Suppose the price in the swap changes from 100 tokens for an NFT to 150 tokens for an NFT
1. User buys an NFT from the marketplace for $100 2. User swaps NFT to tokens in dogeswap (user receives 150 tokens) 3. User sells 150 tokens in raydium for $150
Profit = $150 - $100 = $50
Pool Parameters
vLiquidity Factor: Controls the virtual liquidity added & the price impact & trading range for the respective pair.
Swap Tax: % of fee collected by the protocol for each successful swap.
Arbitrage Tax: % of total arbitrage profits collected as protocol fee.
Arbitrage Revenue share: % of Arbitrage tax distributed to the NFT creators that support the platform by providing liquidity.
Last updated