Skip to content

feat(amm): headless amm_module core Logos module; flip UI to consume it - #232

Open
0x-r4bbit wants to merge 1 commit into
refactor/amm-ffifrom
feat/amm-logos-module
Open

feat(amm): headless amm_module core Logos module; flip UI to consume it#232
0x-r4bbit wants to merge 1 commit into
refactor/amm-ffifrom
feat/amm-logos-module

Conversation

@0x-r4bbit

Copy link
Copy Markdown
Collaborator

Introduce modules/amm — the AMM business logic (resolvePool, swapExactInput, tokenList) as a universal core Logos module that wraps amm_client_ffi and depends on the logos_execution_zone wallet module. The same surface is now consumed by the QML UI (via modules().amm_module) and headlessly (logoscore call amm_module ...).

  • apps/amm: drop the direct amm_client_ffi link; depend on and delegate to amm_module (metadata dependencies, CMakeLists, AmmUiBackend). Wallet-session UI logic stays in the backend.
  • flake.nix: build amm_module via mkLogosModule and inject it into the UI builder's flakeInputs so the dependency resolves.
  • amounts/deadline declared nlohmann::json so the generated dispatch accepts a JSON number (bare small ints on the CLI) or a string (exact u128 from the UI, or a quote-wrapped big value on the CLI); JSON floats are rejected rather than submit a silently-rounded amount.
  • AMM_DEBUG-gated tracing for the swap path.
  • modules/amm/README.md: headless prerequisites + full logoscore recipe.

@0x-r4bbit
0x-r4bbit requested a review from gravityblast July 22, 2026 11:57
@0x-r4bbit
0x-r4bbit force-pushed the feat/amm-swap-onchain branch from 1fd73f8 to 7f17e06 Compare July 23, 2026 11:32
@0x-r4bbit
0x-r4bbit changed the base branch from feat/amm-swap-onchain to main July 23, 2026 17:55
@0x-r4bbit
0x-r4bbit force-pushed the feat/amm-logos-module branch from 483c9db to b147882 Compare July 28, 2026 13:15
@0x-r4bbit
0x-r4bbit changed the base branch from main to refactor/amm-ffi July 28, 2026 13:16
@0x-r4bbit
0x-r4bbit marked this pull request as ready for review July 28, 2026 13:16
Comment thread apps/amm/src/AmmUiBackend.cpp
Comment thread modules/amm/src/amm_module_impl.cpp Outdated
Comment thread modules/amm/README.md Outdated
Comment thread modules/amm/src/amm_module_impl.cpp
Comment thread modules/amm/src/amm_module_impl.cpp Outdated
Comment thread modules/amm/src/amm_module_impl.cpp Outdated
…I to consume it

Introduce modules/amm — the AMM business logic as a universal core Logos module,
consumed identically by the QML UI (via modules().amm_module) and headlessly
(logoscore call amm_module ...). The module is a thin transport adapter: the
domain math lives in the Rust amm_client crate (the transport-independent JSON
FFI), and the module sequences those pure ops with chain I/O delegated to the
logos_execution_zone wallet module. It reaches the same shared wallet instance
the UI opened (Basecamp loads core modules as singletons; standalone the
LogosAPI client cache dedups the connection), so it never opens a second wallet.

The module owns the full AMM surface — not just swaps:
- resolvePool / swapExactInput / tokenList (the swap path)
- newPositionContext / quoteNewPosition / submitNewPosition (add-liquidity)

apps/amm: delete the app-side orchestration (SwapRuntime, NewPositionRuntime,
AmmClient/BundledAmmClient) and the amm_client link. AmmUiBackend now owns only
wallet-session lifecycle and forwards every AMM slot to modules().amm_module.
The one wallet-keyset mutation add-liquidity needs — creating a fresh LP holding
— stays in the backend (via its wallet provider, keeping the account model and
on-disk storage coherent): the module returns "requires_fresh_lp" without
submitting, the backend creates the account and resubmits with its id.

flake.nix / CMakeLists / metadata: the module links the amm_client crate; the UI
links no external lib and depends on amm_module (injected into the UI builder's
flakeInputs so the dependency resolves).

- amounts/deadline declared nlohmann::json so the generated dispatch accepts a
  JSON number (bare small ints on the CLI) or a string (exact u128 from the UI,
  or a quote-wrapped big value on the CLI); JSON floats are rejected rather than
  submit a silently-rounded amount.
- AMM_DEBUG-gated tracing for the swap path.
- Drop tests/cpp/NewPositionRuntimeTest.cpp with the class it covered
  (module-level tests to follow).
- modules/amm/README.md: architecture, headless prerequisites, logoscore recipe.
@0x-r4bbit
0x-r4bbit force-pushed the feat/amm-logos-module branch from b147882 to f46dc7a Compare July 30, 2026 13:08
@0x-r4bbit

Copy link
Copy Markdown
Collaborator Author

@3esmit Addressed your comments

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.

2 participants