-
Notifications
You must be signed in to change notification settings - Fork 125
[Protocol 3.8] AMM v2 - Mirage #2432
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Brecht, could you share your simulation scripts so the team can run the program for better understanding of how the trades/joins/exists work?
packages/loopring_v3/contracts/amm/libamm/AmmTransactionReceiver.sol
Outdated
Show resolved
Hide resolved
All code I have used is available here: https://github.com/Loopring/team/issues/163 |
packages/loopring_v3/contracts/amm/libamm/AmmTransactionReceiver.sol
Outdated
Show resolved
Hide resolved
packages/loopring_v3/contracts/amm/libamm/AmmTransactionReceiver.sol
Outdated
Show resolved
Hide resolved
This comment has been minimized.
This comment has been minimized.
packages/loopring_v3/contracts/amm/libamm/AmmTransactionReceiver.sol
Outdated
Show resolved
Hide resolved
That's correct. If the operator doesn't transfer the necessary funds to L2 to do the exit, Alice will have to withdraw her LP tokens and force the exit on L1 which forced the operator to make the necessary funds available on L2 at the risk of shutting down the pool if he still refuses. If he still refuses the pool shuts down and all funds can be withdrawn to the pool on L1 without the help of the operator. |
|
Brecht, I think we are over-designing the L1 liquidity feature and making things unnecessarily complicated with the current approach. Assuming there is an AssetManager contract on L1 for managing some users' assets. The AssetManager can be designed to allow Loopring Exchange owner to make capital calls to withdraw some assets from L1 defi and automatically deposit these assets to L2 to join a predetermined Amm pool (Capital returns can also be done by the exchange owner on L2 to return funds to AssetManager and later trigger an L1 DeFi deposit). The assets in the same AssetManager can also be called for multiple pools. I think what we need to add on top of Loopring 3.6 is simply a way to deposit-then-join a pool from L1 for contract addresses with on-chain approvals. In other words, from an AMM pool's perspective, the AssetManager address is a regular address, there is no need to handle its deposit/withdrawals/joins/exits differently. What makes such AssetManager interesting is its authorization to Loopring exchange for using its assets with a higher priority than the L1 DeFi apps. |
|
I think that may work (though I have some uncertainties for people that join the pool directly). If this works than the benefit of this method is that it would be opt-in if or even in which defi app the user wants to store his funds (could also be a downside that it is opt-in and probably more expensive from L2). Moves some extra complexity to the AssetManager to manage user funds instead of just working on the pool level, but that seems fine. It seems like a more significant change compared to the system in this PR which works exactly the same way as it works now for all users, but a caspian style system would also do more on L1 so I guess that works out. I'm still thinking about the details how to make it work as expected. Not sure yet about all the details, especially if users are still able to join directly as well). Let's say the 90% of the funds come from the AssetManager, 10% of the funds come from users on L2.
I think the main idea is pretty close to the caspian design:
The difference with your proposal is that there would still be users that have joined from L2 so that probably complicates things.
Not sure the current method is really that complicated because it really is just withdrawing/depositing from the pool, the joins/exit logic just made it bit more complex than expected (I don't think needing to track the balances on L1 is that bad...). Depending on how we want the AssetManager to work it would shift more complexity there which I think will be comparable.
Joins/exits from contracts are possible using funds on L2. EDIT: If we don't allow joins/exits on the pool directly we can implement a uniswap v3 style tick system on the AssetManager level which would be quite powerful because it would allow us to do everything Uniswap v3 does (allowing users to specify custom price ranges etc... while still only needing a single pool), but even with higher capital efficiency built-in because we can also automatically put unused AMM assets (assets not used by the current tick) in a defi app. So trading fees for assets on L2 in the current tick, defi yields for all other assets on L1. I wouldn't be surprised if some project isn't already working on something like this for Uniswap v3. Anyway, just a thought and I guess that would be even more complex to implement. |
* [AMM] Fix pools with active asset manager * Feedback * Amm v2 - Exit mode and pool reuse (#2450) * AMM v2 - minor improvement over brecht's code (#2458) Co-authored-by: Daniel Wang <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
very minor change suggestions.
https://github.com/Loopring/team/issues/163
Most important practical changes:
For the AMM pools the following was added:
IAmmControllerwhich can implement custom virtual balance logic and can shut down the pool if necessary (needed for hybrid AMM pools which doesn't provide pool liquidity tokens itself).IAssetManager.IAssetManagerwhich can use them productively.So I think all existing pools and all new amplified pools can use the same
IAssetManagerandIAmmControllercontracts, so only a single implementation contract needs to be deployed. After updating the pool contracts with 3.8 the pool virtual balances need to be set to the correct values using the set virtual balances operation of the pool contract.These pool settings are not stored in the AMM pool as storage but as immutable variables baked into the contract because the settings will be shared between many pools:
IAssetManagerwhich can handle all funds of all pools together (e.g. put all ETH of all pools into AAVE). I think it doesn't make sense to do this for each pool separately, funds of each pool are moved to thisIAssetManagercontract so L1 investing costs are shared.IAmmController, making it easy and cheap to do updates to all pools depending on the contract if necessary. Because the logic implemented in the controller contract is rarely used (not for trades/joins/exits) the small extra overhead of doing the logic in an external contract is insignificant. Doing the logic in an external contract also makes it easier for using new data in storage without having to worry about different storage layouts in the pool contract implementations.