Skip to content

chore(amm): validate fee tier in sync_reserves#79

Open
0x-r4bbit wants to merge 1 commit intomainfrom
chore/sync_reserves-fees
Open

chore(amm): validate fee tier in sync_reserves#79
0x-r4bbit wants to merge 1 commit intomainfrom
chore/sync_reserves-fees

Conversation

@0x-r4bbit
Copy link
Copy Markdown
Collaborator

All other entry functions validate the pools fee tier, except for this function. This is likely because it doesn't make use of the fees.

To make the code consistent (and auditing easier), we're now validating the fees in sync_reserves the same way.

All other entry functions validate the pools fee tier, except for this
function. This is likely because it doesn't make use of the fees.

To make the code consistent (and auditing easier), we're now validating
the fees in `sync_reserves` the same way.
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 makes AMM instruction validation consistent by adding fee-tier validation to sync_reserves, aligning it with other AMM entrypoints that already enforce supported fee tiers.

Changes:

  • Import assert_supported_fee_tier into amm/src/sync.rs.
  • Validate pool_def_data.fees in sync_reserves via assert_supported_fee_tier(...).

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

Comment thread amm/src/sync.rs
Comment on lines 14 to +16
let pool_def_data = PoolDefinition::try_from(&pool.account.data)
.expect("Sync reserves: AMM Program expects a valid Pool Definition Account");
assert_supported_fee_tier(pool_def_data.fees);
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.

Agreed. The change is correct, but I recommend to add a small unit test for sync_reserves that sets PoolDefinition.fees = 2 and expects the shared unsupported-fee panic message, cuz the current sync tests do not have this new guard directly.

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 guard looks right and matches the validation already present in add/remove/swap. One small test gap: would be good to narrow amm_program unit test that mutates PoolDefinition.fees to an unsupported value and expects Fee tier must be one of 1, 5, 30, or 100 basis points from sync_reserves.

Comment thread amm/src/sync.rs
Comment on lines 14 to +16
let pool_def_data = PoolDefinition::try_from(&pool.account.data)
.expect("Sync reserves: AMM Program expects a valid Pool Definition Account");
assert_supported_fee_tier(pool_def_data.fees);
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.

Agreed. The change is correct, but I recommend to add a small unit test for sync_reserves that sets PoolDefinition.fees = 2 and expects the shared unsupported-fee panic message, cuz the current sync tests do not have this new guard directly.

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.

3 participants