feat: enhance remove liquidity function to handle surplus balances#16
Closed
3esmit wants to merge 1 commit intologos-blockchain:mainfrom
Closed
feat: enhance remove liquidity function to handle surplus balances#163esmit wants to merge 1 commit intologos-blockchain:mainfrom
3esmit wants to merge 1 commit intologos-blockchain:mainfrom
Conversation
5 tasks
There was a problem hiding this comment.
Pull request overview
This PR updates AMM remove_liquidity to pay exiting LPs pro-rata from live vault balances (thereby distributing accumulated fee surplus), while keeping tracked reserves as the bookkeeping source-of-truth for pool reserves.
Changes:
- Compute remove-liquidity payouts from actual
vault_a/vault_btoken balances and run slippage checks against those actual payout amounts. - Keep reserve accounting based on tracked reserves and add a guard that rejects
vault_balance < tracked_reservestates. - Simplify LP burn semantics to burn exactly the requested LP amount, and add unit + integration coverage for surplus exits and mismatch rejection.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
amm/src/remove.rs |
Uses live vault balances for payout math + slippage checks; burns exact requested LP; asserts reserves do not exceed vault balances. |
amm/src/tests.rs |
Adds unit tests for reserve-vs-vault mismatch panics and surplus-based payout chained calls; updates expected transfer amounts. |
integration_tests/tests/amm.rs |
Adds an integration test covering surplus distribution on remove-liquidity and expected resulting vault/user balances. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
0x-r4bbit
reviewed
Apr 2, 2026
Collaborator
0x-r4bbit
left a comment
There was a problem hiding this comment.
As discussed in #12
Let's first clarify whether we want "recover surplus" in the first place.
Then we can discuss whether we want the changes here.
/cc @gravityblast
Collaborator
|
Closing this for now as #38 has been closed as well. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
remove_liquidityto compute user payouts from the live vault balances while keeping pool reserve bookkeeping based on tracked reservesdelta_lpidentityFixes #15
Replaces logos-blockchain/logos-execution-zone#420
Testing
cargo +1.94.0 test -p amm_program remove_liquidityRISC0_DEV_MODE=1 cargo +1.94.0 test -p integration_tests amm_remove_liquiditycargo +nightly fmt --all -- --checktaplo fmt --check .RISC0_SKIP_BUILD=1 cargo +1.94.0 clippy --workspace --all-targets -- -D warningsRISC0_DEV_MODE=1 cargo +1.94.0 test --workspace --exclude integration_testsRISC0_DEV_MODE=1 cargo +1.94.0 test -p integration_testsNotes
reserve_aandreserve_bremain reserve-based after exit, which preserves any remaining surplus asvault_balance - reservefor the LPs who stay in the poolInstruction, IDL, guest entrypoint, or account-schema changes in this PR