Joystream / joystream

Joystream Monorepo
http://www.joystream.org
GNU General Public License v3.0
1.43k stars 115 forks source link

AMM Design Discussion #3754

Open bedeho opened 2 years ago

bedeho commented 2 years ago

Background

Great work with this overview @ignazio-bovo

https://hackmd.io/@msgSgRNqSKmkYgN4EoybcA/BysDdI8Iq

First thoughts

  1. It seems to me the best tradeoff here would be something that never is really bad, but works Ok in a wide range of circumstances, which would be Linear? It's also way easier for people to understand.
  2. When it says that Initial Liquidity bootstrapping capabilities are very good, does this not mean that its simply really cheaply selling off the tokens to buyers, which is at the expense of the issuer?
  3. I think we should just pick a single type of curve for our first implementation, adding additional curves in the future will be very easy, no migration needed, and it will be with the benefit of more concrete information.
  4. Ok, so a tax on both AMM transaction types.
  5. Price based slippage constraint seems most direct and simple, but is it the same as is used on say Uniswap? may be wise to just stick with their exact same version of slippage tolerance, as people already know this.
ignazio-bovo commented 2 years ago

It seems to me the best tradeoff here would be something that never is really bad, but works Ok in a wide range of circumstances, which would be Linear? It's also way easier for people to understand. I think we should just pick a single type of curve for our first implementation, adding additional curves in the future will be very easy, no migration needed, and it will be with the benefit of more concrete information.

Linear would stand somewhat in the middle of all described tradeoffs. I think it is a good choice for initial experimentation since it is not largely exposed to one risk in particular

When it says that Initial Liquidity bootstrapping capabilities are very good, does this not mean that its simply really cheaply selling off the tokens to buyers, which is at the expense of the issuer?

No I used that term to specify that price growth is the fastest in the beginning of a project. So early investors can benefits of larger price upswings with respect to early investors. This is effectively an incentive to buy early rather than late. This effectively doesn't keep CRT price low for long, if selling initial CRT for cheap is desired polynomial curves are more suitable.

Price based slippage constraint seems most direct and simple, but is it the same as is used on say Uniswap? may be wise to just stick with their exact same version of slippage tolerance, as people already know this.

Yes Uniswap, Pancakeswap and similar (constant product market makers) use the same slippage protection mechanism, namely tolerance % + execution deadline. (Uniswap allows you to set these parameters in expert mode)

bedeho commented 2 years ago

Background

The following research

https://github.com/joystream/atlas/issues/2728

Conclusions

  1. vesting schedule for AMMs should be optional specified by issuer, and it is aligned with point of purchase of $CRT. Obviosuly like sale vesting, it must be specified in a way which is agnostic to actual purchase amount, as that is only known at time of purchase.
  2. patronage rate at time of issuance must be lower than some global stored upper bound.
  3. curve shape must be more gradual, so just y(x)=ax+b.
  4. user must be able to specify b, namely initial $JOY price.
  5. there must be some function f which is used to set a=f(Q) where Q is the issuance, otherwise the curve will not make sense. To me f(Q) = p/Q for some global stored p.
  6. it should be possible to turn off an AMM any time if you are issuer, $JOY is burned.

Questions

I suspect the way a is picked needs some work.

ignazio-bovo commented 2 years ago

About parameter 'a'

If you look at the mathematical proof for the Bancor formula it looks to me with alpha = 1 (in their notation) their value for a would be initial supply / initial_price i.e. is an arbitrary constant. I would suggest:

Will it be possible for a issuer to also restart the AMM anytime after or the issuer can just start and turn off the AMM only once in the CRT lifetime?

vesting schedule for AMMs should be optional specified by issuer, and it is aligned with point of purchase of $CRT

Does this means that after any account purchases amount X from the bonding curve (=> supply is increased by X at one time) X is then vested to the account over a block period ?

Lezek123 commented 2 years ago

Some questions/thoughts:

Question: Do we want new CRT to be minted during AMM or do we want AMMs to be backed by existing CRT, just like sales?

I think the latter is preferable, because otherwise we're introducing another possibility of minting and diluting existing tokens, other than the patronage (which has a clear, predictable yearly rate, so it's not really a problem). This opens up a lot of opportunities for misuse, for example, creator can do the initial sale and then "take back" the the channel reward cut by diluting tokens through series of AMMs, where he can cheaply buy (mint) his own tokens.

If we were to force AMMs to be backed by existing CRT, another advantage of that would be that in this case creator cannot sell any tokens that were used to back the AMM, unless he buys them back himself, meaning that the creator doesn't have to opt into a vesting schedule during issuance to prove he's not going to "rug pull", he can just start an AMM backed by all the tokens he issued and he would only be able to participate in the AMM on the same conditions that everyone else can (ie. if he buys, he will be bound by a vesting schedule specific to that AMM).

it should be possible to turn off an AMM any time if you are issuer, $JOY is burned.

If the JOY from the AMM is burned, this means there is almost no incentive for the creator to sell tokens through AMM, other than to find out how much JOY are people willing to pay for his CRT before selling it through Token Sale.

Question: Do we actually expect the AMMs to be treated only as means to measure the demand before starting Token Sale, not as an actual source of revenue for the creator?

My initial understanding was that we want the creator to be able to earn JOY for the tokens sold through AMM, same way he can earn JOY when doing a Token Sale.

There are actually two ways the creator could possibly earn from the AMM:

I suppose that regardless of whether we require AMMs to be backed by existing CRT or we allow minting new CRT through AMM (which as I mentioned before, is probably not a good idea), we would have some limit of how many tokens can be bought on a given AMM.

For simplicity I'll assume we just have AMMs backed by existing CRT, so if someone starts an AMM with 1_000_000 CRT on sale, then obviously no more than 1_000_000 CRT can be bought.

If we want to stick to linear curve I can see two options and both have their pros an cons.

First let's define some variables:

Now on how to determine a:

bedeho commented 2 years ago

Replying to @ignazio-bovo here

we allow (advanced) users to specify his preferred value of `a'

I don't think this really fits with our user base and context. We are dealing with users that are not sophisticated traders, this is why we have an AMM design to begin with, and they are just trying to buy/sell easily. If there is a diversity of a values out there, it can be hard for people to understand how buying into different tokens may be very different. So we really shuold try to avoid a situation where AMMs are very different from each other.

However, this does beg the question, what if the $USD price of $JOY is drifting substantially over time, then then in those terms, the curve may be getting steeper or more shallow. I don't see an easy way to avoid this until we have a stablecoin integration, and anyway there seemed to be no reprots of this being a problem in DeSo or Rally.

Will it be possible for a issuer to also restart the AMM anytime after or the issuer can just start and turn off the AMM only once in the CRT lifetime?

Yeah I guess so. I am not sure we really need a direct restart feature, like as an extrinsic, directly.

Does this means that after any account purchases amount X from the bonding curve (=> supply is increased by X at one time) X is then vested to the account over a block period ?

It was intended to mean that we have the exact same arrangement, with cliff+linear vesting period, as if when someone buys X from a sale with a vesting condition, but that the vesting is aligned at point of purchase, not termination of sale.

bedeho commented 2 years ago

Replying to @Lezek123

Do we want new CRT to be minted during AMM or do we want AMMs to be backed by existing CRT, just like sales?

So the former in our and those other designs.

I see the case for the other variety, but my hunch is that the benefit of the AMM model is that it provides long term liquidity without running out or tying up the creator assets in perpetuity, but I am speculating. Given that we already have the sale model, and the other deployed models people are happy with, I think its best to stick with it.

creator can do the initial sale and then "take back" the the channel reward cut by diluting tokens through series of AMMs, where he can cheaply buy (mint) his own tokens.

I see your point here, but

and we can also make this much harder if we block starting an AMM which has a starting price lower than any previous AMM on that channel with at least one sale, unless an explicit governance decision is made to lower this number for this specific channel.

What do you think?

If the JOY from the AMM is burned, this means there is almost no incentive for the creator to sell tokens through AMM, other than to find out how much JOY are people willing to pay for his CRT before selling it through Token Sale.

I did not understand why you say this, perhaps you missed that the burning happens when you "shut off" the AMM, not during normal purchasing of $CRT, and its only the creator who can do this.

Does you question still hold?

Do we actually expect the AMMs to be treated only as means to measure the demand before starting Token Sale, not as an actual source of revenue for the creator?

They are not a source of revenue, because $JOY used to purchase $CRT is just held by AMM, its not sent to creator. Token sales are a source of revenue though.

I expect them to be used as the most convenient way for an audience to get exposure to interesting assets, either because a sale is too much work, or its in the past, or because the demand at any given time is too low and unpredictale to warrant the overhead, etc. The user research has really confirms that people do find it solves their problem on this front.

My initial understanding was that we want the creator to be able to earn JOY for the tokens sold through AMM

No they cannot.

There are actually two ways the creator could possibly earn from the AMM

Yes, but we have no included any of those.

we would have some limit of how many tokens can be bought on a given AMM.

That is not clear to me, why can't the AMM just sell more and more at increasing marginal prices?

Option 1 vs Option 2

I think for similar reasons to my answer to @ignazio-bovo, we have to go with standardization and enforcement here.

The other issue here is you are assuming there is a c, which is not part of any of the AMM designs for such tokens, and I am not sure we should deviate.

ignazio-bovo commented 2 years ago

I still have a couple of questions, after reading Leszek response.

Should we allow AMM to be opened after Sales?

If we allow AMM to be opened after a sale, the following situation might happens:

  1. A buys 10 CRT by paying 1 JOY (via Sale @ unit price = .1 JOY/CRT)
  2. Sale is terminated
  3. A gets his total CRT amount (10 CRTs), either immediately or he waits until the vesting period is over
  4. AMM is opened with a = 1 and b = .1
  5. B bonds 10 CRT for 50 + 1 = 51 JOYs (I have used the pricing mechanism for linear curve)
  6. A unbonds his 10 CRT and gets 51 JOYs
    Result

    A profits by 41 JOYs B loses by 51 JOYs Creator profits by 10 JOYs Is this acceptable

    Concurrent supply events

    The CRT total supply gets modified by one of the following event accross CRT lifetime: a. initial creator allocation b. patronage credit minted c. tokens burned by creator d. tokens unbonded e. tokens bonded Now amm_supply = (d) - (e) creator_share = (a) + (b), hence CRT total_supply = amm_supply + creator_share - (c) There is the possibility of a creator having creator_share liquid CRTs for which he can attempt a rug pull, independently on how many CRTs have been bonded/unbonded

bedeho commented 2 years ago

Should we allow AMM to be opened after Sales?

Yes.

If we allow AMM to be opened after a sale, the following situation might happens:

I did not really understand the principle involved in this example, where a & b values are coming from, which we have not 100% settled yet. But certainly, if starting price for an AMM is not constrained, then you can start a new AMM with arbitrarily low price, which undercuts a prior sale. This is not in principle incorrect or bad, but it can be abused in some cases. But see my comment in reply to @Lezek123 above

we can also make this much harder if we block starting an AMM which has a starting price lower than any previous AMM on that channel with at least one sale, unless an explicit governance decision is made to lower this number for this > specific channel.

There is the possibility of a creator having creator_share liquid CRTs for which he can attempt a rug pull, independently on how many CRTs have been bonded/unbonded

I don't really understand the question here? Are you asking if the creator can sell into AMM with liquid $CRT? yes. Can this be abused, yes. Does this mean we should not do AMMs or somehow try to block the creator from selling liquid $CRT to AMM? I don't think so.

I also want to point at that (a) does not impact AMM, as its before, and (b) will be constrained to be small in relative terms. Also keep in mind anyone can burn tokens, not just creator.

bedeho commented 2 years ago

Setting values and constraints for a & b

Revisiting this topic, so I think we must really stick with a platform enforced values here, and there has to be away to both set and constrain these which has some sort of semantic content that operators can reason about. That is what I am trying to suggest here.

Idea

The market maker is constructed so as to charge pruchasing for $JOY in accordance with some hypothetical fair market value of the creator asset based on its fundamental potential for revenue cashflows.

Derivation

We start with the assumptions that

Let C denote the total cost, in $JOY, of purchasin Q units starting from q=0, which means that

C = Integral[y, 0 , Q] = Q*b + Q*a*Q/2

Now observe that if you do this purchase, you hold 50% of the total $CRT supply, meaning you have a claim on F*R/2 via revenue splits, hence based on our idea we say

C = F*R/2

From this equation we can find a formula for a, namely

Q*b + Q*a*Q/2 = F*R/2 <-> Q*a*Q/2 = F*R/2 - Q*b <-> a = 2*(F*R/2 - Q*b)/Qˆ2

Notice that this equation also yields a bound on b in order to make a > 0, namely

a > 0 <-> 2*(F*R/2 - Q*b)/Qˆ2 > 0 <-> F*R/2 - Q*b > 0 <-> -Q*b > -F*R/2 <-> b < F*R/2Q

Conclusion

Notes

ignazio-bovo commented 2 years ago

Please verify the math is correct

The math is correct

The $JOY denominated fundamental value market cap of the coin is F.

Suppose creator wants to start AMM at block height t then F will have the following semantics

revenue up to block t for creator (from nft sales, royalties etc...) + (discounted) expected value of future earnings

If F is as above then the methodology proposed is correct on paper. Here's the drawbacks that I think comes with this:

EDIT: In the above method basically $a = a(R, F)$, where:

bedeho commented 2 years ago

$R$ is established by the creator. I am not sure if we want to vary or to be constant across splits

Is immutable after issuance, this has already been decided long ago, split code has already been merged as well.

$F$ is chosen by the governance, which might be wrong in computing the channel fundamental values at the outset. This is a risk for the creator.

Yes, I agree. We could allow the creator to set when creating AMM, and for example have a default vale used if one is not set, and this default is set by governance?

ignazio-bovo commented 2 years ago

Discontinuities

Consider the scenario Suppose we have fixed a curve $ax + b = f(x)$ for the AMM functionality. This will result in

$$ \frac{a}{2} x^2 + b x + c = F(x)$$

  1. Alice activates AMM functionality and sale functionality
  2. Initially Alice sell $x_1$ tokens to Bob via sale at a price $y_1/x_1$ so that Bob gets $y_1$ JOYs worth of CRTs
  3. Bob then unbonds $x_2$ via the AMM cashing out $y_2$ with an arbitrage profit of $y_2 - y_1$

image

The above situation becomes even more complicated when considering interplay between several rounds of patronage minting, sales and revenue splits, and it is not possible to fix a AMM equation that works for the scenario.

Solution