chore(amm): add defensive check for lp token solvency#78
Open
chore(amm): add defensive check for lp token solvency#78
Conversation
This check is added to fulfill the program invariant that no more tokens than owned can be burned. This was not a bug before, because the `token` program will revert on `Transfer::Burn` when one tries to burn more tokens than available. So this change is merely for making the invariant explicit.
3esmit
reviewed
May 4, 2026
| pool_def_data.liquidity_pool_supply > MINIMUM_LIQUIDITY, | ||
| "Pool only contains locked liquidity" | ||
| ); | ||
| assert!( |
Collaborator
There was a problem hiding this comment.
The guard is the right place for this invariant. Can we add a direct amm_program unit test that expects Remove amount exceeds user LP balance? The existing integration test only asserts generic failure and would still pass if this explicit AMM-side check regressed back to relying on the downstream token burn.
3esmit
reviewed
May 4, 2026
Collaborator
3esmit
left a comment
There was a problem hiding this comment.
This PR is fine, but I suggest adding test to ensure this won't be accidentally removed.
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.
This check is added to fulfill the program invariant that no more tokens than owned can be burned. This was not a bug before, because the
tokenprogram will revert onTransfer::Burnwhen one tries to burn more tokens than available.So this change is merely for making the invariant explicit.