Skip to content

chore(amm): add defensive check for lp token solvency#78

Open
0x-r4bbit wants to merge 1 commit intomainfrom
chore/remove-lp-check
Open

chore(amm): add defensive check for lp token solvency#78
0x-r4bbit wants to merge 1 commit intomainfrom
chore/remove-lp-check

Conversation

@0x-r4bbit
Copy link
Copy Markdown
Collaborator

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.

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.
@0x-r4bbit 0x-r4bbit requested review from 3esmit and gravityblast May 4, 2026 12:51
Comment thread amm/src/remove.rs
pool_def_data.liquidity_pool_supply > MINIMUM_LIQUIDITY,
"Pool only contains locked liquidity"
);
assert!(
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Collaborator

@3esmit 3esmit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR is fine, but I suggest adding test to ensure this won't be accidentally removed.

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.

2 participants