Derive swap direction from signed input holding#208
Open
3esmit wants to merge 1 commit into
Open
Conversation
There was a problem hiding this comment.
Pull request overview
This PR refactors the AMM swap interface to derive swap direction from the signed “input” user holding account (instead of a separate token_definition_id_in argument), updates the guest instruction surface + IDL accordingly, and adds/updates tests to validate the new account ordering and role constraints.
Changes:
- Remove
token_definition_id_infromSwapExactInput/SwapExactOutputand derive direction fromuser_holding_in’s token definition. - Update guest instruction accounts so only
user_holding_inis marked assigner, and reorder swap accounts to(user_holding_in, user_holding_out). - Add/adjust tests to cover wrong output definitions, duplicate in/out holdings, and signer expectations.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| programs/integration_tests/tests/amm.rs | Updates swap instruction construction/account ordering and adds integration coverage for signer behavior. |
| programs/amm/src/tests.rs | Extends unit tests to validate new input/output holding validation rules and removes old token_definition_id_in plumbing. |
| programs/amm/src/swap.rs | Implements swap direction derivation + user account validation based on signed input holding and output definition matching. |
| programs/amm/methods/guest/src/bin/amm.rs | Updates guest instruction interface to (user_holding_in signer, user_holding_out) and removes token_definition_id_in. |
| programs/amm/core/src/lib.rs | Updates instruction docs and removes token_definition_id_in fields from the core instruction enum. |
| artifacts/amm-idl.json | Regenerates IDL to reflect renamed accounts, signer flag change, and removed argument. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
6b718d1 to
75d51c6
Compare
7a1b4f1 to
bea6d64
Compare
Use token_definition_id_in as the swap direction selector while allowing callers to authorize only the selected input holding. Update AMM IDL metadata and integration coverage for input signatures, token-id mismatches, swapped holding slots, and exact-output swaps.
bea6d64 to
7d1ed57
Compare
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
Fixes #207
user_holding_inanduser_holding_out.token_definition_id_in.user_holding_inas signer in the guest instruction surface and regenerated AMM IDL.Breaking Changes
SwapExactInputandSwapExactOutputno longer accepttoken_definition_id_in.