Files
lez-programs/modules/amm/flake.nix
T
r4bbit 23963b22f0 feat(amm): move all AMM logic into the amm_module core module; flip UI 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.
2026-08-03 15:39:56 +02:00

30 lines
1.3 KiB
Nix

{
description = "Logos AMM core module — headless AMM business logic (pool resolution + swaps)";
inputs = {
logos-module-builder.url = "github:logos-co/logos-module-builder";
# Core wallet module dependency. The input name must match the
# metadata.json `dependencies` entry so the builder resolves it as a module
# dependency. Same fork the repo-root flake pins (the QtRO byte-string
# `instruction` fix for send_generic_public_transaction).
logos_execution_zone.url = "github:gravityblast/logos-execution-zone-module?ref=fix/generic-tx-instruction-bstr";
};
# NOTE: like apps/amm, this flake is NOT built standalone. The amm_client
# crate this module links (the Rust JSON-FFI brain) lives in the repo-root
# flake, and referencing it from here would require a hardcoded `git+file://`
# path or a `path:../..` input — the latter fails flake evaluation because this
# dir is copied into the Nix store as its own flake root, so `../..` can't
# escape it. Instead, the repo-root flake.nix builds this module directly
# (src = ./modules/amm) and resolves amm_client via `self`. Build it from
# the repo root:
# nix build .#amm-module
outputs = inputs@{ logos-module-builder, ... }:
logos-module-builder.lib.mkLogosModule {
src = ./.;
configFile = ./metadata.json;
flakeInputs = inputs;
};
}