peerplays-network / pips

PeerPlays Improvement Proposals
12 stars 3 forks source link

[In Editing] DEX with Automated Liquidity Pools #11

Open jonathanbahai opened 3 years ago

jonathanbahai commented 3 years ago

DEX with Automated Liquidity Pools

PIP: 11
Title: DEX with Automated Liquidity Pools
Authors: Jonathan Baha'i <jbahai@freedomledger.com>
Status: Draft
Type: Informational
Created: 20-12-22

DEX - The Peerplays dex is very similar to Bitshares with one major difference, it is designed to only support PPY pairing. This was done to prevent Peerplays from turning into a shitcoin factory which has happened everywhere else.

Liquidity Pools / AMM - A feature which has not been implemented in Peerplays with several variations of LP/AMM available in various markets for different purposes. Our LP should be designed to serve the purpose of enabling coins/tokens which exist within Peerplays to be able to instantly ‘swap’ to pay for fees within the network, and also to provide liquidity to the network.

Eg. Suppose there is PIZZA, HOTDOGS, ETH, EOS, HIVE, BTC on Peerplays. If I only have ETH in my account and want to be able to send ETH to another peerplays user, and have no PPY, the transaction should go through an instant swap and complete the transfer without the end user needing to buy/hold PPY.

Likewise, if I am trading on the Peerplays DEX and only have ETH and want to trade only against ETH, I want to be able to view the pairs in ETH, I can thanks to the Peerswap LPs. Even though the DEX has all pairs in PPY, I can still trade in ETH based on the LP available for ETH.

Eg. I want to place an order for PIZZA on the dex (a trade, hold the pepperoni), and only have ETH in my balance. I can place the order to BUY Pizza and my ETH through the LP is converted to PPY and then placed on the order book.

This means that for all pairs within Peerplays the DEX volume becomes pooled into the PPY pairing and prevents fractional pools while generating more transactional volume for the LPs which translates into more profits for those that provide it. win/win/win.

This positions Peerplays DEX and LPs as a value add to all the other coins/tokens worldwide by providing a fast/easy use platform that can operate within their core preferred asset instead of forcing others to adopt PPY.

For example, if I wanted to create a DEX interface that was just for all the tokens to pair to BTC, I can easily do that and never reveal PPY as the underlying asset for fees. I could likewise, create one for PIZZA, or EOS.. and so on. I believe these interfaces will become personalized as we go into the future based on peoples community preferences and lifestyle and therefore we will provide the tools to support that.

How Liquidity Pools Work in Peerplays

I have only kept my understanding of LPs and AMM at a high level in order to keep myself from getting too far into the weeds of what others are doing and instead focus on the practical needs of what Peerplays requires for its purposes. We want LPs/AMM that matches our objectives. So please contribute any additional details I may be missing or need to be addressed in order to complete it.

Any token within the Peerplays network (including SONs) can create a pool. The ownership of the pool depends on the liquidity providers and the token owner. If it is a decentralized asset, then parameters would fall to the Advisors, where private assets would fall to the asset owner.

I will use BTC as an example since this is what is coming soon to Peerplays.

I have 10 BTC and I deposit it to my Peerplays account.

I wish to see my BTC grow (who doesn’t?)

I want to deposit 9BTC into the LP and earn rewards, so I PowerUP and input 9BTC for my balance. My 9 BTC gets confirmed by the liquidity pool contract and I receive an NFT token with the details that includes the date of creation, and the exact amount of BTC deposited.

Graphical representation of these NFTs should be considered also as this will impact peoples sense of ownership.

I now qualify for participation rewards in Peerplays. This means when I vote for witnesses, I now can gain rewards, when anyone requires a Peerswap of BTC/PPY, I will get rewards.

My NFT (I like to call this GPOS NFT to be specific) can be burned and I can get my BTC back, but only on a timed schedule. The smaller the stake the sooner it can be withdrawn, the larger, the longer. This should be relative to all other NFTs. and using a straight curve increases the time of lockup linear in coindays.

If however, I wish to liquidity immediately without delay, I can always put my GPOS NFT up for sale on the NFT marketplace. Someone else could buy it and I can see a profit from the potential future rewards even by the sale of the asset. Similar to how a company is sold with a multiplier to consider future revenues, a GPOS NFT could ask a similar premium.

Wait, where is the PPY coming from?

When PPY holders PowerUP they can select the pool they wish to support. If there was say BTC, ETH, PIZZA, HOTDOG, and EOS available, if I had say 1000 PPY I could then PowerUP say 100PPY to BTC, 100PPY to ETH, and 800PPY to PIZZA (because it's delicious).

Advisor controlled LPs will have the backing of the reserve pool against the other side and will have the rewards that accumulate from this go back to the reserve pool.

This means that the 9BTC I put into the pool now has the same backing from the reserve pool assuming there was no one who supported the pool with their PPY (hard to imagine).

Users PPY in the pool will be first to receive rewards and the network only will when the LP goes below user funding.

The end result is a process flow that is frictionless for the end user, and insured.

How are the rewards calculated?

This is a tricky part that I am still struggling with. My understanding is that as far as the LP is concerned, with every swap that takes place, we can expect at 0.3% or something to that effect being deducted from the transaction to go to the LP.

My initial design was to have the rewards then target NFT holders according to the staking power of their NFT relative to the whole pool. If my 9BTC was all that was in the pool for PPY/BTC, then I would get 50% of all fee rewards generated, and the other 50% would go to the reserve pool.

This is rather simplistic and doesn’t incorporate some necessary gamification elements that would help a great deal. For example, I believe that a bell curve on rewards should be implemented in order to encourage the median middle rather than all reward flow going to minnows (encourages them to put more in), or the whales (discourages them from taking over the whole thing and instead spreads out more).

It would be ideal if this curve was calculated based on NFT backing assets and then targeted with a curve of 5/15/60/15/5. The look of the NFT could be programmed to change when they enter into the different ‘levels’ with the most ideal being the 60 zone.

How are the fees calculated?

Because the core asset is PPY, when I deposited my 9 BTC I also had the fee paid in PPY. This means that when the rewards are paid out, they are also paid out in PPY. I can however select to have my payout in BTC, but that would be another swap, and I am paying for that.

How is the price discovered? (AMM)

I believe that price discovery should happen in the DEX by taking the price over a 30 minute period and then publishing it. I believe this is what is most optimal in regular markets and based on a study of Moonieswap found this to be more in favor of LPs vs. arbitrage bots. If there is a better way to do this please add. I don’t believe we should be feeding prices from other networks as they are prone to manipulation and attack of the system by way of manipulating other low volume inputs. Given the high amount of liquidity which should be achieved with our pairs, it would serve as the most reliable price discovery which can be independently verified.

TBC...

Feedback is welcome during this drafting of this proposal. Please join in dev discussion by leaving comments below.

sierra19XX commented 3 years ago
  1. If a user has to get his reserve token (token for which he provided liquidity eg. BTC) back, there shouldn't be an impermanent loss. How do the impermanent loss guarding work in the model?
  2. What's the role of DEX here, isn't AMM just enough for the purpose?
  3. Are these going to be dynamically weighted pools (as opposed to 50:50 Uniswap pools)?
  4. If these are dynamically weighted pools, in order to align the staked and current reserve balance of a token, there needs to be an attractive fee which should also be dynamic in order to attract arbitrageurs, can we include this part as well if relevant?
  5. Does the chain provide any staking of PPY to pools as insurance against impermanent loss?
  6. If I'm not wrong, the core idea behind 'a user can get his reserve token back from the pool' is impermanent loss guarding, if there are no external feeds of prices how are we going to achieve this?
  7. Without external price feeds there will always be a difference between the market and on-chain prices of tokens.

I will probably add more as I go over the write-up multiple times .....

jonathanbahai commented 3 years ago
  1. If a user has to get his reserve token (token for which he provided liquidity eg. BTC) back, there shouldn't be an impermanent loss. How do the impermanent loss guarding work in the model?

I may not have detailed this in the first draft. I believe the markets should be insured by the reserve pool of the blockchain with a maximum of 300% of the user contributed pool. This means if only 100 PPY is contributed to the LP, and someone wants to add say 300 PPY of value in BTC, then it will be accepted with reserve pool now adding 200PPY into the pool. Rewards then proportionally flow back to the reserve pool also.

NOTE: If there isn't enough assets from the users in the LP + insurance to ensure impermanent loss, then the contract will not accept additional asset without the addition of PPY. For example, if a market already has say 10 BTC and the equal value of PPY from both users and insurance is in there already, and someone attempts another swap frrom BTC > PPY then the contract prompts to add more PPY to the pool first, which can be done from the DEX at it's current market price.

  1. What's the role of DEX here, isn't AMM just enough for the purpose?

The AMM works on an algo of price discovery and will algo price out orders based on the volume of the order. However, the DEX is the free market where spot trades can be placed to gain discovery of price. The AMM can derive this as a source in their also and also participate in the DEX as added liquidity to market positions to better insure a velocity of markets to reflect a more accurate reflection of trade value.

  1. Are these going to be dynamically weighted pools (as opposed to 50:50 Uniswap pools)?

I been waiting for your analysis on this actually before I formed any opinions around this. I think from a user perspective the 50:50 is easier to understand, and potentially less prone to calculation errors. I maybe wrong on that though.

  1. If these are dynamically weighted pools, in order to align the staked and current reserve balance of a token, there needs to be an attractive fee which should also be dynamic in order to attract arbitrageurs, can we include this part as well if relevant?

The fee can be set by the Advisors and changed based on market requirements/conditions. I agree the fee should be attractive. In this type of system it is many more smaller transactions and less about trade.

  1. Does the chain provide any staking of PPY to pools as insurance against impermanent loss?

That was my answer to question #1. Yes.

  1. If I'm not wrong, the core idea behind 'a user can get his reserve token back from the pool' is impermanent loss guarding, if there are no external feeds of prices how are we going to achieve this?

DEX price discovery will provide this as I mentioned above.

  1. Without external price feeds there will always be a difference between the market and on-chain prices of tokens.

I will probably add more as I go over the write-up multiple times .....

The DEX is on-chain, so we can have price discovery from this.

bobinson commented 3 years ago

The DEX is on-chain, so we can have price discovery from this.

With no external validation the prices can get skewed compared to the external markets ?

jonathanbahai commented 3 years ago

The DEX is on-chain, so we can have price discovery from this.

With no external validation the prices can get skewed compared to the external markets ?

The combination of AMM algorithm in open market DEX combined with external traders likely running their own bots (dexbot for eg.) Will keep markets tracing closely to any external sources.

Because of the combined liquidity the velocity will be better than other external markets i believe.