Skip to content

refactor(apps/amm): move the amm_client crate into modules/amm/ffi as… - #238

Open
0x-r4bbit wants to merge 2 commits into
feat/amm-logos-modulefrom
refactor/move-ffi
Open

refactor(apps/amm): move the amm_client crate into modules/amm/ffi as…#238
0x-r4bbit wants to merge 2 commits into
feat/amm-logos-modulefrom
refactor/move-ffi

Conversation

@0x-r4bbit

Copy link
Copy Markdown
Collaborator

… amm_ffi

After the amm_module refactor, this crate is linked only by the module (the UI delegates to modules().amm_module and links nothing), so its home under apps/amm/ and the name "client" were both misnomers: it's the AMM business logic the module wraps, reached across an FFI boundary — the same relationship logos_execution_zone has with wallet_ffi. Co-locate it with the module that owns it and name it for that role.

The FFI surface is unchanged — the exported functions are already amm_* (not amm_client_*) — so only the crate, directory, generated header, dylib, and package names move. The module's call sites are untouched; it just includes the renamed header.

  • apps/amm/client → modules/amm/ffi (git-tracked rename; history preserved)
  • crate amm_client → amm_ffi: package name, include/amm_ffi.h, libamm_ffi.dylib, AMM_FFI_H guard, build.rs output path, tests/public_api.rs import
  • workspace member path + Cargo.lock
  • flake.nix: pname, -p, header-copy path, dylib install_name, packages.amm_ffi, ammModuleOutputs externalLibInputs, DYLD wrapper
  • modules/amm: metadata external_libraries, CMakeLists EXTERNAL_LIBS, impl #include + comments, README, flake note
  • apps/amm/flake.nix: drop the now-dead amm_client external-lib input (the UI links no external lib of its own)

Resulting layout:
modules/amm/
src/ # C++ module (amm_module_impl.{h,cpp})
ffi/ # Rust crate amm_ffi (Cargo.toml, src/, include/amm_ffi.h)

…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.
… amm_ffi

After the amm_module refactor, this crate is linked only by the module (the
UI delegates to modules().amm_module and links nothing), so its home under
apps/amm/ and the name "client" were both misnomers: it's the AMM business
logic the module wraps, reached across an FFI boundary — the same relationship
logos_execution_zone has with wallet_ffi. Co-locate it with the module that
owns it and name it for that role.

The FFI surface is unchanged — the exported functions are already amm_* (not
amm_client_*) — so only the crate, directory, generated header, dylib, and
package names move. The module's call sites are untouched; it just includes the
renamed header.

- apps/amm/client → modules/amm/ffi (git-tracked rename; history preserved)
- crate amm_client → amm_ffi: package name, include/amm_ffi.h, libamm_ffi.dylib,
  AMM_FFI_H guard, build.rs output path, tests/public_api.rs import
- workspace member path + Cargo.lock
- flake.nix: pname, -p, header-copy path, dylib install_name, packages.amm_ffi,
  ammModuleOutputs externalLibInputs, DYLD wrapper
- modules/amm: metadata external_libraries, CMakeLists EXTERNAL_LIBS, impl
  #include + comments, README, flake note
- apps/amm/flake.nix: drop the now-dead amm_client external-lib input (the UI
  links no external lib of its own)

Resulting layout:
  modules/amm/
    src/   # C++ module  (amm_module_impl.{h,cpp})
    ffi/   # Rust crate  amm_ffi  (Cargo.toml, src/, include/amm_ffi.h)
@0x-r4bbit
0x-r4bbit requested review from 3esmit and gravityblast July 29, 2026 14:00
@0x-r4bbit
0x-r4bbit force-pushed the feat/amm-logos-module branch from b147882 to f46dc7a Compare July 30, 2026 13:08
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.

1 participant