Skip to content

[Loopring 3.6] Demo AMM pool #1737

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Sep 22, 2020
Merged

[Loopring 3.6] Demo AMM pool #1737

merged 16 commits into from
Sep 22, 2020

Conversation

Brechtpd
Copy link
Contributor

@Brechtpd Brechtpd commented Sep 13, 2020

  • L1/L2 joins + L1/L2 exits
  • Transferable liquidity tokens on L1.

@Brechtpd
Copy link
Contributor Author

One thing to keep in mind if we would allow changing the weights is that we shouldn't do so just based on what LPs deposit. If previous liquidity LPs were okay with a 50/50 pool that does not mean they are fine with being in a pool that is suddenly a 90/10 pool (which changes the risks completely) just because some LPs only want to deposit one of the tokens. If an LP only wants to provide a single token they could do so, but the weights should remain the same (like balancer does), unless a more advanced curve is just probably using oracles.

Another thing is I think that we should really try to just use signature based joins/exits instead of needing Ethereum transactions by users (cheap and flexible). One of the difficulties here is with layer 1 balances and locking those. Currently this works kind of okay, but I think things can be made simpler when we by default lock all tokens up in the contract, and people need to unlock them (so the inverse what I do now for the amounts being deposited, having them unlocked by default and only locking them when they will be used). The other possibility here is that we only support joins from layer 2 + default locked behaviour of the liquidity tokens on layer 1 so they can be withdrawn only when specifically unlocked with some delay or with the help of a signature of the operator.

@Brechtpd Brechtpd marked this pull request as ready for review September 17, 2020 22:19
@dong77
Copy link
Contributor

dong77 commented Sep 18, 2020

Brecht, it will be ideal if the operator of the exchange can choose to skip some Join/Exit requests to avoid being Sybil attacked.

@dong77
Copy link
Contributor

dong77 commented Sep 18, 2020

Is the reason for introducing poolAmountOut and poolAmountOut to allow the user to quit joining/exiting the pool if the price has changed a lot?

What's the worst thing that may happen if we remove the two parameters and calculate the number of liquidity tokens to mint/burn automatically?

@dong77
Copy link
Contributor

dong77 commented Sep 18, 2020

Update: Basically we want to make the AmmPool contract getting closer to what we desire for production. The feedback from the relayer team is that they prefer using a map instead of a queue for the join/exit requests, such that the operator of the exchange can choose which join/exit requests to process and in which order.

@Brechtpd
Copy link
Contributor Author

Brecht, it will be ideal if the operator of the exchange can choose to skip some Join/Exit requests to avoid being Sybil attacked.

Joins we can skip, but on-chain exit requests will all need to be processed to make sure people can exit the pool, same as with forced withdrawals on the exchange. Offchain requests > onchain requests in all normal cases though, so hopefully these onchain requests will rarely be used.

Is the reason for introducing poolAmountOut and poolAmountOut to allow the user to quit joining/exiting the pool if the price has changed a lot?

Especially for withdrawing is makes a lot of sense to just let users specify how many of their liquidity tokens they want to redeem back to tokens. Otherwise we/they have to approximate how many tokens need to be withdrawn to burn the required amount of liquidity tokens, it would be almost impossible for people to burn all their liquidity tokens like that.

For joins I think not specifying it would be okay (maybe even better in some cases when the pool is small and amounts being deposited), still some other safety checks need though I think.

What's the worst thing that may happen if we remove the two parameters and calculate the number of liquidity tokens to mint/burn automatically?

I think only some additional slippage losses when the pool is in an unbalanced state or is brought into an unbalanced state. But I think if we do things differently than uniswap/balancer we should have very good reasons to do so, seems needlessly risky otherwise.

Update: Basically we want to make the AmmPool contract getting closer to what we desire for production. The feedback from the relayer team is that they prefer using a map instead of a queue for the join/exit requests, such that the operator of the exchange can choose which join/exit requests to process and in which order.

Offchain requests > onchain requests, I don't want us to actually use these onchain requests. :)

To support this we'll have to switch to lock all users funds by default. So do we want to handle this in the pool contract or do we just deposit funds directly to the exchange so we don't have to worry about that? This way we only need to really support joins from layer 2. Though for the liquidity tokens themselves, if we always want to keep them on L1, we'd still have to have some locking mechanism in the pool as well.

dong77 and others added 5 commits September 18, 2020 16:43
@Brechtpd
Copy link
Contributor Author

#1771

Brechtpd and others added 4 commits September 19, 2020 11:29
* rename variables

* extract methods

* extract methods
* add changes based on my questions

* more

Co-authored-by: wangdong <wangdong@zhongan.io>
Co-authored-by: Brechtpd <Brechtp.Devos@gmail.com>
* [protocol 3.6] Changed approvals + locking logic

* [protocol 3.6] LP tokens

* [protocol 3.6] Use minPoolAmountOut for joins

* [protocol 3.6] AMM pool signature assisted L1 withdrawals + fixes

* [protocol 3.6] Small improvements/fixes
@Brechtpd Brechtpd merged commit c918b16 into master Sep 22, 2020
@Brechtpd Brechtpd deleted the protocol36-ammpool branch September 22, 2020 03:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants