Skip to content

Feat/amm registry - #335

Merged
0x-r4bbit merged 11 commits into
mainfrom
feat/amm-registry
Sep 2, 2026
Merged

Feat/amm registry#335
0x-r4bbit merged 11 commits into
mainfrom
feat/amm-registry

Conversation

@0x-r4bbit

Copy link
Copy Markdown
Collaborator

No description provided.

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 an AMM “registry” configuration path to the AMM UI so known tokens/pools can be sourced either from existing local JSON files or from a single multi-network registry document (with a simple disk cache), and refreshes can propagate to QML via a revision counter.

Changes:

  • Introduces RegistryLoader (local-over-remote resolution, remote fetch + disk cache, network selection + deployment guard).
  • Wires RegistryLoader into AmmUiBackend and exposes registryRevision + refreshRegistry() so QML can re-fetch lists when the snapshot updates.
  • Updates testnet setup script to emit a single-file registry for exercising AMM_REGISTRY_URL, and updates QML pages to reload lists when registryRevision changes.

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
artifacts/amm-registry.json Adds an on-repo registry JSON document/template.
apps/amm/tests/testnet/setup-amm-testnet.sh Writes a test-only single-file registry and documents how to use AMM_REGISTRY_URL locally.
apps/amm/src/RegistryLoader.h Declares new loader interface for registry-backed token/pool snapshots.
apps/amm/src/RegistryLoader.cpp Implements local/remote loading, network selection, deployment checks, and disk caching.
apps/amm/src/AmmUiBackend.rep Exposes registryRevision and refreshRegistry() over QtRO for QML consumers.
apps/amm/src/AmmUiBackend.h Adds RegistryLoader member and new refreshRegistry() slot.
apps/amm/src/AmmUiBackend.cpp Replaces direct file parsing with RegistryLoader snapshot and revision propagation.
apps/amm/qml/pages/SwapPage.qml Reloads token list when registryRevision changes.
apps/amm/qml/pages/PoolsPage.qml Reloads pool list when registryRevision changes.
apps/amm/qml/pages/LiquidityPage.qml Reloads resolved tokens when registryRevision changes.
apps/amm/CMakeLists.txt Adds RegistryLoader sources and links Qt Network.
apps/amm/.gitignore Ignores test-generated amm-registry.json.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +9 to +12
class QNetworkAccessManager;
class QJsonArray;
class QJsonObject;

Comment thread apps/amm/src/RegistryLoader.cpp Outdated
return true;
if (m_connectedAmm.isEmpty() && m_connectedToken.isEmpty())
return true;
return amm == m_connectedAmm && token == m_connectedToken;
Comment thread apps/amm/src/RegistryLoader.cpp
Comment thread apps/amm/tests/testnet/setup-amm-testnet.sh Outdated
"name": "Logos AMM registry",
"version": "0.1.0",
"timestamp": "2026-08-27T00:00:00Z",
"networks": [],
@0x-r4bbit

Copy link
Copy Markdown
Collaborator Author
Screenshot 2026-08-31 at 12 56 19

Split the AMM UI's known-tokens/known-pools loading into two concerns:

- reading raw JSON bytes from a source (`readConfigFileBytes`, currently a
  local file at TOKENS_CONFIG / AMM_POOLS_CONFIG), and
- parsing those bytes into the UI list (`parseTokensJson` / `parsePoolsJson`).

The parsers are now source-agnostic, so a remote payload can feed the exact
same validation and shaping. No behavior change: the local-file env-var path
is preserved, including the fail-soft / skip-malformed-entry semantics.
Introduce apps/amm/src/RegistryLoader, a QObject that owns the known-tokens /
known-pools snapshot and serves it to the backend's QtRO slots. The JSON
parsers move here; AmmUiBackend now reads tokenList/poolList/resolveTokens from
the loader's snapshot instead of re-parsing the config files inline.

Add the refresh plumbing the UI will drive:
- PROP(int registryRevision READONLY) — bumped on every snapshot refresh so
  QML replicas re-fetch the lists.
- SLOT(void refreshRegistry()) — manual re-load.

No behavior change: the source is still the local TOKENS_CONFIG / AMM_POOLS_CONFIG
files. This is Phase 2a of docs/amm-registry-plan.md; Phase 2b reshapes
RegistryLoader::refresh() into the async remote (AMM_REGISTRY_URL) fetch —
manifest + deployment guard + disk cache — with the same snapshot contract.
When no local TOKENS_CONFIG / AMM_POOLS_CONFIG is set, RegistryLoader now loads
the known-tokens / known-pools from a remote GitHub registry named by
AMM_REGISTRY_URL: an async QNetworkAccessManager fetch of a registry.json
manifest, then the tokens.json / pools.json it points at (resolved relative to
the manifest URL).

- Stale-while-revalidate: the on-disk cache is served immediately and
  revalidated against the network (the manifest `timestamp` is the freshness
  key); a failed/offline fetch keeps the last cache.
- Deployment guard: a manifest whose programIds don't match the app's deployment
  (from configAccount) is rejected; a manifest that omits programIds is trusted.
- Precedence unchanged: local files replace the remote source when set; user
  custom tokens still merge on top.
- registryRevision bumps on each snapshot update; SwapPage/PoolsPage/
  LiquidityPage re-fetch on it. CMake links Qt6::Network.

Add apps/amm/registry-sample/ — a manifest plus empty tokens.json / pools.json
and a README — to exercise the remote path end to end (start with the empty
case). Compile-verified via `nix build .#amm-ui`; not yet run end to end.
Replace the per-network manifest + separate tokens.json/pools.json with a single
Uniswap-token-list-style document: { networks:[{id,name,programIds}],
tokens:[{network,...}], pools:[{network,...}] }. RegistryLoader now fetches one
file, selects the active network, and filters entries to it.

- Active network = AMM_NETWORK (override) -> else the network whose programIds
  match the connected deployment (configAccount) -> else the lone network. The
  programIds match doubles as the deployment guard.
- Registry lives in-repo at artifacts/amm-registry.json (no separate repo yet);
  remove apps/amm/registry-sample/.
- Rename setExpectedProgramIds -> setConnectedProgramIds (drives selection + guard);
  add activeNetwork(). Local dev source (bare arrays) is unchanged.

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 16 out of 16 changed files in this pull request and generated 2 comments.

Comment thread modules/amm/src/amm_module_impl.cpp
Comment on lines +100 to +108
Button {
id: saveButton
objectName: "settingsRegistrySaveButton"
Layout.fillWidth: true
text: qsTr("Save")
onClicked: {
if (root.backend)
root.backend.saveRegistryUrl(registryUrlField.text)
}
setup-amm-testnet.sh now also writes tests/testnet/amm-registry.json — the seeded
tokens/pools in the single-file multi-network registry shape (one "local" network
with empty programIds so the lone-network rule auto-selects it; holding-agnostic
tokens; a fresh timestamp each run). This lets the AMM_REGISTRY_URL path be
exercised against the local sequencer without hosting anything — point
AMM_REGISTRY_URL at the file with a file:// URL.
…ntime

The module derives its program id from AMM_PROGRAM_BIN. Add setAmmProgramId so a
caller can adopt a specific id instead — the app uses it to target the network it
selected from its registry, dropping the AMM_PROGRAM_BIN requirement.
ammProgramId() prefers the adopted id and falls back to the bin when none is set,
so headless callers are unaffected.
RegistryLoader no longer infers the network from the connected deployment (which
needed AMM_PROGRAM_BIN and can't tell apart networks that share deterministic
program/account ids). It selects by AMM_NETWORK, or the lone network when the
registry declares exactly one, and exposes that network's amm program id via
activeAmmProgramId(). AmmUiBackend adopts it on the module with setAmmProgramId
whenever the snapshot changes, so ops target the selected network with no bin. A
multi-network registry now requires AMM_NETWORK to disambiguate.

The testnet setup script writes the freshly deployed program ids into the local
registry network and drops AMM_PROGRAM_BIN from the remote-registry launch line.
Add a registryUrl PROP and saveRegistryUrl SLOT to the backend, backed by a global
(per-user) QSettings value ("Logos"/"AmmUI"). RegistryLoader falls back to this
configured URL when AMM_REGISTRY_URL is unset, so a packaged build needs no env
var. saveRegistryUrl persists the value and reloads the registry; the disk cache is
now keyed by the effective URL (env or configured) so it stays consistent. The
config-field UI comes in the next commit.
Add a "Registry settings" entry to the wallet menu that opens a page with a text
field bound to the backend's registryUrl and saved via saveRegistryUrl. A packaged
build can now set the registry URL in the UI instead of via AMM_REGISTRY_URL, which
still overrides when set. The menu opens when a wallet is connected.
The timestamp only fed a revalidation skip: a re-fetch reused the current snapshot
when the document's timestamp matched the last applied one. Nothing polls in the
background — a fetch happens only at startup, on manual refresh, or on a URL change
— so the skip saved almost nothing and could wrongly skip a switch between two
registries that happened to share a timestamp. Remove the field and always apply a
fetched registry; the disk cache keeps its stale-while-revalidate behavior (keyed
by URL, no stamp). Drop the timestamp from the setup script and the sample registry.
Add a cogwheel in the bottom-right corner that opens an app settings modal with a
Registry section: the known-tokens / known-pools registry URL (a persisted global
setting) and a network picker over the registry's networks, defaulting to the
first. This is AMM-specific, so it lives in the app rather than the shared wallet
UI. Bound to the backend's registryUrl / saveRegistryUrl / networks /
activeNetwork / selectNetwork.
@0x-r4bbit
0x-r4bbit merged commit 6956b23 into main Sep 2, 2026
7 checks passed
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.

3 participants