Skip to content

Derive swap direction from signed input holding#208

Open
3esmit wants to merge 1 commit into
mainfrom
amm-signed-input-swap-v2
Open

Derive swap direction from signed input holding#208
3esmit wants to merge 1 commit into
mainfrom
amm-signed-input-swap-v2

Conversation

@3esmit

@3esmit 3esmit commented Jun 29, 2026

Copy link
Copy Markdown
Collaborator

Summary

Fixes #207

  • Refactor AMM swap instructions to use user_holding_in and user_holding_out.
  • Derive swap direction from the signed input holding's token definition and remove token_definition_id_in.
  • Mark only user_holding_in as signer in the guest instruction surface and regenerated AMM IDL.
  • Add role validation for non-pool input tokens, wrong output definitions, duplicate input/output accounts, and missing input signatures.

Breaking Changes

  • SwapExactInput and SwapExactOutput no longer accept token_definition_id_in.
  • Swap callers must pass the debited user holding first and the recipient holding second.

Copilot AI review requested due to automatic review settings June 29, 2026 14:22

Copilot AI left a comment

Copy link
Copy Markdown

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 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_in from SwapExactInput / SwapExactOutput and derive direction from user_holding_in’s token definition.
  • Update guest instruction accounts so only user_holding_in is marked as signer, 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.

Comment thread programs/amm/src/swap.rs Outdated
Comment thread programs/integration_tests/tests/amm.rs Outdated

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Comment thread programs/integration_tests/tests/amm.rs
@3esmit 3esmit requested review from 0x-r4bbit and gravityblast June 29, 2026 17:04
@3esmit 3esmit force-pushed the amm-signed-input-swap-v2 branch 2 times, most recently from 7a1b4f1 to bea6d64 Compare July 2, 2026 20:19
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.
@3esmit 3esmit force-pushed the amm-signed-input-swap-v2 branch from bea6d64 to 7d1ed57 Compare July 3, 2026 12:42
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.

Refactor AMM swaps to use one signed input holding

2 participants