Skip to content

Remove Redundant active Flag From AMM PoolDefinition#44

Merged
0x-r4bbit merged 1 commit intomainfrom
amm/task/remove-active-flag
Apr 14, 2026
Merged

Remove Redundant active Flag From AMM PoolDefinition#44
0x-r4bbit merged 1 commit intomainfrom
amm/task/remove-active-flag

Conversation

@3esmit
Copy link
Copy Markdown
Collaborator

@3esmit 3esmit commented Apr 10, 2026

Fixes #25

Summary

This PR removes the redundant active flag from amm_core::PoolDefinition and replaces its callers with explicit liquidity_pool_supply checks.

After the minimum-liquidity lock, active no longer tracked anything meaningfully distinct from pool initialization, so the AMM now makes those readiness checks directly from LP supply at each call site.

Changes

  • remove active from the serialized PoolDefinition schema
  • update new_definition to reject any existing pool definition with nonzero LP supply
  • update swap_exact_input, swap_exact_output, sync_reserves, and remove_liquidity to gate on explicit minimum-liquidity checks instead of active
  • update AMM unit and integration fixtures to use zero-supply or below-minimum-liquidity states explicitly
  • refresh comments and panic messages so they describe LP-supply semantics instead of active/inactive status

Testing

  • cargo +1.94.0 test -p amm_program
  • RISC0_DEV_MODE=1 cargo +1.94.0 test -p integration_tests --test amm
  • cargo +nightly fmt --all -- --check
  • taplo fmt --check .
  • RISC0_SKIP_BUILD=1 cargo +1.94.0 clippy --workspace --all-targets -- -D warnings
  • RISC0_DEV_MODE=1 cargo +1.94.0 test --workspace --exclude integration_tests
  • RISC0_DEV_MODE=1 cargo +1.94.0 test -p integration_tests

Notes

  • This PR intentionally changes the serialized PoolDefinition layout by removing active, so older serialized pool bytes are not schema-compatible with this version.
  • This PR does not fold in issue Remove dead re-initialization code path from new_definition #26. The current zero-supply reinitialization branch in new_definition remains as a follow-up cleanup risk.

Copilot AI review requested due to automatic review settings April 10, 2026 18:38
@3esmit 3esmit self-assigned this Apr 10, 2026
@3esmit 3esmit requested a review from 0x-r4bbit April 10, 2026 18:38
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR removes the redundant active field from amm_core::PoolDefinition (and its serialized layout) and updates the AMM to gate “pool readiness” using explicit liquidity_pool_supply checks (primarily against MINIMUM_LIQUIDITY), with corresponding fixture/test updates.

Changes:

  • Removes active from PoolDefinition and updates docs/comments to describe LP-supply-based readiness semantics.
  • Updates new_definition to reject initialization when the existing pool has nonzero LP supply.
  • Replaces active checks with explicit liquidity_pool_supply minimum-liquidity checks in swap/sync/remove flows; updates unit and integration tests/fixtures accordingly.

Reviewed changes

Copilot reviewed 7 out of 8 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
amm/core/src/lib.rs Removes active from the serialized PoolDefinition schema and updates related docs.
amm/src/new_definition.rs Replaces active gating with liquidity_pool_supply == 0 precondition for initialization/reinit.
amm/src/swap.rs Updates swap validation to require liquidity_pool_supply >= MINIMUM_LIQUIDITY.
amm/src/sync.rs Updates sync gating to require liquidity_pool_supply >= MINIMUM_LIQUIDITY.
amm/src/remove.rs Updates remove-liquidity gating to require liquidity_pool_supply >= MINIMUM_LIQUIDITY and removes active field updates.
amm/src/tests.rs Refactors unit test fixtures and expected panic messages to use LP-supply semantics.
integration_tests/tests/amm.rs Refactors integration fixtures and test names to remove active and model zero-supply/below-min states explicitly.
amm/methods/guest/src/bin/amm.rs Updates instruction docs to reference “existing zero-supply” reinitialization semantics.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@3esmit 3esmit force-pushed the amm/task/remove-active-flag branch from 3eeb2e9 to d2edb75 Compare April 10, 2026 18:43
@3esmit
Copy link
Copy Markdown
Collaborator Author

3esmit commented Apr 10, 2026

@copilot comments are valid, however in the context of #26 they are not an issue, as this code will be further refactored to remove reinit paths, we don't need to address those changes, as they would be removed in #26

Copy link
Copy Markdown
Collaborator

@0x-r4bbit 0x-r4bbit left a comment

Choose a reason for hiding this comment

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

Change LGTM!

Only thing I'd ask is to mark this change as a breaking change in the commit message (we're removing a field in the pool definition)

@3esmit 3esmit force-pushed the amm/task/remove-active-flag branch from d2edb75 to 1adbd43 Compare April 13, 2026 14:26
@3esmit
Copy link
Copy Markdown
Collaborator Author

3esmit commented Apr 13, 2026

mark this change as a breaking change in the commit message (we're removing a field in the pool definition)

Added a ! as first character of the commit message.

@3esmit 3esmit requested a review from 0x-r4bbit April 13, 2026 14:27
@0x-r4bbit
Copy link
Copy Markdown
Collaborator

@0x-r4bbit 0x-r4bbit force-pushed the amm/task/remove-active-flag branch from 1adbd43 to 6bd7900 Compare April 14, 2026 09:47
…plicit flag

Remove the `active: bool` field from `PoolDefinition` and replace it with an
implicit invariant: a pool is considered active when
`liquidity_pool_supply >= MINIMUM_LIQUIDITY`.

BREAKING CHANGE: `PoolDefinition` Borsh serialization format has changed.
Existing on-chain pool accounts encoded with the `active` field are
incompatible with this version.

Closes #25
@0x-r4bbit 0x-r4bbit force-pushed the amm/task/remove-active-flag branch from 6bd7900 to 8259c18 Compare April 14, 2026 09:48
@0x-r4bbit
Copy link
Copy Markdown
Collaborator

@3esmit updated the commit message for you and rebased. Will merge once green.

@0x-r4bbit 0x-r4bbit merged commit 4a9a441 into main Apr 14, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

active flag in PoolDefinition is redundant after MINIMUM_LIQUIDITY lock

3 participants