3-way Constant Product
A 3-way Constant Product market is created where
constant = yes_balance * no_balance * invalid_balance.
The first liquidity provider buys 1000 complete sets from Augur and adds all shares to the CP market. This would result in
constant = 1000000000 = 1000 * 1000 * 1000, and it would equate to a price of 0.33 for YES, 0.33 for NO, and 0.33 for INVALID.
The first trader believes that the odds for YES are higher than 33%, so they would buy 100 complete sets and trade NO to the CP market in exchange for YES shares. They would keep the INVALID shares for themselves as insurance against INVALID. This requires solving for
1000000000 = (1000 - yes) * (1000 + 100) * 1000 which would result in
yes = 90. Therefore, the user would pay 100 DAI and walk away with 190 fully insured YES shares resulting in an average price per share of 0.5263 DAI / share. The market would be left with 909 YES, 1100 NO, 100 INVALID. It is worth noting that in this example INVALID is priced at 33%, which is incredibly high, so the value of the INVALID shares that the user kept are what causes the price per share to higher than 0.33 for the user.
Another trader shows up (perhaps using a different UI because they want to trade INVALID specifically) and thinks 33% chance of INVALID is way too high for the market and wants to short INVALID. They would buy 1000 complete sets and trade INVALID shares to the CP market in exchange for YES + NO shares.
1000000000 = (909 - yes) * (1100 - no) * (1000 + 1000)
The user is shorting INVALID here, so they want to get out a number of YES/NO shares proportionate to the current odds.
yes = no * (909 / 1100)
We can now solve the equation by getting down to a single variable
1000000000 = (909 - (no * 909 / 1100)) * (1100 - no) * (1000 + 1000)
1000000000 / 2000 = (909 * 1100) - (909 * no) - (1100 * no * 909 / 1100) + (no * no * 909 / 1100)
(909/1100) * no^2 - 1818 * no + 999900 = 500000
(909/1100) * no^2 - 1818 * no + 499900 = 0
We can see that this is a quadratic equation which has two solutions of
1878. We know that
1878 isn't possible (out of range) so we know that
no = 322. With that, we can now solve for
yes = no * 909 / 1100
yes = 322 * 909 / 1100
yes = 266
So in exchange for 1000 shares of INVALID, the user would receive 322 no shares and 266 yes shares and the market would be left with
1000000000 = 643 * 778 * 2000 (note: the above rounds in a few places, so this isn't exact and that is OK, we just need to make sure that in the contracts the rounding is consistently in favor of liquidity providers). The ratio of YES:NO was 909:1100 before the trade, and 643:778 after the trade which is the same (caveat: rounding) so the liquidity pool maintained its YES/NO valuation (only the INVALID valuation changed), and the trader acquired YES/NO shares proportionate to their current value, and only shorted INVALID.
Seeding Liquidity with Alternative Odds
It is worth noting that in most cases, the liquidity provider would actually hold on to some outcome shares so the market wasn’t seeded with 0.33/0.33/0.33 odds. The INVALID odds there are especially unlikely.
Naively, this can be achieved by setting up the market at even odds, and then having the liquidity provider be the first trader and short INVALID. You can optimize this with a bit of mathing such that the liquidity provider just plugs in an initial ratio and it will seed appropriately and hold excess shares automatically. For the sake of discussion, I think it is easier to think about having the LP always start with even odds and then trade the price to target.
- The liquidity provider has to be long some shares if they want to seed the market with alternative odds. It is possible to avoid this with a formula like Balancer uses, but while solving a quadratic equation is hard enough, throwing in there fractional exponents makes it nearly insurmountably hard because that requires logarithms, which are hard to do on Ethereum.
- As with all market making of prediction markets, since all of the shares except for one will go to 0 (exception for scalar markets), the liquidity provider must exit their position before the outcome is known in order to prevent themselves from getting wiped out. This problem isn’t unique to constant product AMMs, but it also isn’t solved by them.
- Solving a quadratic equation on-chain isn’t simple. It is possible and not terribly difficult, but since there are no native constructs for it you will have to use a library, and the gas costs will potentially be something that need to be considered.
2-way Constant Product Alternative
The market could just be a YES/NO market and the liquidity provider could hold their INVALID shares just like all other users. For an MVP, this is probably a good choice as it simplifies things and avoids the need to solve a quadratic equation. If the market ends up INVALID, the liquidity provider, and every user that traded on the platform, would get essentially a full refund (minus Augur reporting fees).
- This system will struggle to identify invalid markets like the Augur v2 UI is planning on doing (by looking for INVALID shares trading at a higher rate than expected) because INVALID is not traded at all, it is just held by traders and market makers as insurance. On the flip side, it doesn’t really matter if the market is invalid because everyone is insured and gets a full refund, so there is really no opportunity for scamming, just trolling.
- You cannot take all of your profits early. You can take profits out up to your insured amount, but after that you have to hold some position until market close. This is because in order to close out a position, you need to complete a set, and if you buy YES low and then sell YES high, that means you’ll end up with more YES+NO shares than you have INVALID shares. You’ll be able to close out your YES shares with the platform up to the number of INVALID shares you hold (taking profits up to how much you put in), and any excess YES shares you have beyond that you’ll end up holding as part of an incomplete set (either as YES, NO, or YES+NO). If the market continues to move you can continue to trade freely on it, you just cannot exit to DAI for more than you entered with unless you can convince someone to sell you their insurance.