Derive swap direction from signed input holding - #208
Merged
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.
3esmit
force-pushed
the
amm-signed-input-swap-v2
branch
from
June 29, 2026 15:35
6b718d1 to
75d51c6
Compare
3esmit
force-pushed
the
amm-signed-input-swap-v2
branch
3 times, most recently
from
July 3, 2026 12:42
bea6d64 to
7d1ed57
Compare
Collaborator
Author
|
Approved. |
… input Replace the `token_definition_id_in` argument with a role-based account interface: swaps now take a `user_input_holding` and a `user_output_holding` instead of positional token-A/token-B holdings. Direction is derived from the input holding's own token definition, and the input slot is a framework-level `#[account(signer)]` so authorization is enforced before execution rather than delegated solely to the downstream token transfer. The output holding only receives and needs no signature. This removes the ambiguity the previous arg-based model carried (the arg could disagree with the signed holding) and makes the IDL express the signing rule: `user_input_holding` is `signer: true`, `user_output_holding` is `signer: false`. The two user-holding post-states are echoed in the guest's declared slot order (input, then output); the framework matches post-states to accounts by position, so the internal A/B mapping used for reserve bookkeeping must not leak into the returned order. BREAKING CHANGE: The AMM swap instruction interface changed and the guest ImageID/ProgramId changes as a result.
0x-r4bbit
force-pushed
the
amm-signed-input-swap-v2
branch
from
July 21, 2026 07:04
adff15b to
860b48c
Compare
0x-r4bbit
approved these changes
Jul 21, 2026
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.