Skip to content

feat(wallet): add reusable program account selector - #242

Closed
3esmit wants to merge 5 commits into
mainfrom
feat/shared-wallet-token-holding-selector
Closed

feat(wallet): add reusable program account selector#242
3esmit wants to merge 5 commits into
mainfrom
feat/shared-wallet-token-holding-selector

Conversation

@3esmit

@3esmit 3esmit commented Jul 30, 2026

Copy link
Copy Markdown
Collaborator

Closes #241.

Adds a generic shared-wallet program account selector. It can filter any program account type by a decoded state field, so it can be reused for more than TokenHoldings.

The first use covers every AMM TokenHolding choice:

  • swap input and output
  • liquidity token A and token B inputs
  • LP TokenHolding output

The highest-balance matching holding is selected automatically. Users can choose another holding. Outputs also offer Create new TokenHolding, which is selected automatically when no matching output exists.

Screenshots

Swap input — highest balance selected from two matching holdings:

Swap input TokenHolding selector

Swap output — existing destination or new TokenHolding:

Swap output TokenHolding selector

Liquidity token A input:

Liquidity token A TokenHolding selector

Liquidity token B input:

Liquidity token B TokenHolding selector

LP TokenHolding output — Create new selected when no matching holding exists:

LP TokenHolding output selector

Checks: formatting, Clippy, workspace unit tests, full integration tests, QML tests, IDL drift, AMM UI build, and live AMM UI walkthrough against a synced testnet wallet.

@0x-r4bbit

Copy link
Copy Markdown
Collaborator

Depends on #240. The humanized-wallet PR should land first.

@3esmit please make this based on main instead.
The wallet UX PR "humanized wallet" needs more time to analyse and decide on.

@3esmit
3esmit force-pushed the feat/shared-wallet-token-holding-selector branch from 00b5328 to db0c0b8 Compare August 3, 2026 16:02
@3esmit

3esmit commented Aug 3, 2026

Copy link
Copy Markdown
Collaborator Author

rebased to main, fixed failing test, and loosened coupling to IDL code from humanized wallet.

@3esmit
3esmit force-pushed the feat/shared-wallet-token-holding-selector branch from db0c0b8 to 6086d65 Compare August 4, 2026 13:54
@3esmit
3esmit marked this pull request as ready for review August 4, 2026 16:08
Copilot AI lite review requested due to automatic review settings August 4, 2026 16:08

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

Adds a shared-wallet “program account selector” UI primitive and wires it through the AMM UI so users can pick which wallet-owned TokenHolding accounts to use as inputs/outputs (including “create new” outputs), while extending the AMM swap instruction path to support swapping into a fresh, authorized output holding.

Changes:

  • Add ProgramAccountSelector QML control (with C++/QML tests) that filters by account type + decoded state field and auto-selects highest-balance matches.
  • Expose wallet TokenHoldings as generic programAccounts in AMM context/quote flows; add holding selection + LP destination selection fields to requests.
  • Update AMM swap to accept a fresh authorized output holding, with new unit/integration tests and updated instruction docs.

Reviewed changes

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

Show a summary per file
File Description
programs/integration_tests/tests/amm.rs Adds an integration test proving swap-exact-input can initialize a fresh output holding.
programs/amm/src/tests.rs Adds unit tests for accepting/rejecting fresh output holdings in swap-exact-input.
programs/amm/src/swap.rs Implements “owned-by-token-program OR fresh+authorized” validation for swap holdings.
programs/amm/methods/guest/src/bin/amm.rs Updates guest-facing instruction documentation for fresh output holdings.
programs/amm/core/src/lib.rs Updates core instruction docs to reflect fresh+signed output holding option.
modules/amm/ffi/src/api/tests.rs Expands FFI tests for holding selection defaults/overrides and LP destination behaviors.
modules/amm/ffi/src/api/swap.rs Updates swap plan generation to require output-holding signing (see review comment).
modules/amm/ffi/src/api/request.rs Extends PositionRequest to carry selected holding IDs + LP destination choice flags.
modules/amm/ffi/src/api/quote.rs Adds holding/LP destination selection logic and exposes LP destination options in quote JSON.
modules/amm/ffi/src/api/holding.rs Refactors holding selection to support explicit requested holding IDs and sorted options.
modules/amm/ffi/src/api/context.rs Exposes wallet TokenHoldings as generic programAccounts and includes per-token holdings.
modules/amm/ffi/src/api/accounts.rs Threads LP holding selection into the missing-account plan and source tracking.
apps/shared/wallet/tests/qml/tst_ProgramAccountSelector.qml Adds QML coverage for selector filtering, auto-selection, create-new behavior, and u128-safe comparisons.
apps/shared/wallet/tests/cpp/LogosWalletProviderTest.cpp Adjusts expectation for instruction serialization representation.
apps/shared/wallet/qml/ProgramAccountSelector.qml Introduces reusable selector control used by AMM swap and liquidity flows.
apps/shared/wallet/CMakeLists.txt Exposes the new selector as part of the shared wallet QML public surface.
apps/amm/tests/qml/tst_TokenAmountInput.qml Adds QML tests validating holding auto-selection and manual selection.
apps/amm/tests/qml/tst_NewPositionForm.qml Updates tests to include programAccounts and verify holding IDs propagate into requests.
apps/amm/src/AmmUiBackend.rep Updates token list config docs to deprecate legacy “holding” and use wallet TokenHoldings.
apps/amm/README.md Updates user-facing docs: token config no longer requires per-token holding addresses.
apps/amm/qml/pages/SwapPage.qml Wires programAccounts from backend context into the swap UI.
apps/amm/qml/components/swap/TokenVisuals.js Updates comment to reflect token config no longer includes holdings.
apps/amm/qml/components/swap/TokenInput.qml Adds holding selector UI for swap inputs/outputs using ProgramAccountSelector.
apps/amm/qml/components/swap/SwapCard.qml Uses selected holdings for swap submission; supports creating a fresh output holding before swap.
apps/amm/qml/components/liquidity/TokenAmountInput.qml Adds holding selector UI for liquidity token inputs and exposes selected holding state to the form.
apps/amm/qml/components/liquidity/NewPositionForm.qml Adds holding selection + LP destination selector and threads selections into quote requests and submission gating.

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

Comment thread programs/amm/src/swap.rs
Comment thread modules/amm/ffi/src/api/swap.rs
@3esmit
3esmit force-pushed the feat/shared-wallet-token-holding-selector branch from 6086d65 to 9233eff Compare August 10, 2026 14:25
@0x-r4bbit

Copy link
Copy Markdown
Collaborator

This has landed with #284

@0x-r4bbit 0x-r4bbit closed this Aug 11, 2026
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.

Allow wallet users to choose TokenHolding inputs and outputs

3 participants