Skip to content

Feat/amm registry - #335

Open
0x-r4bbit wants to merge 5 commits into
mainfrom
feat/amm-registry
Open

Feat/amm registry#335
0x-r4bbit wants to merge 5 commits into
mainfrom
feat/amm-registry

Conversation

@0x-r4bbit

Copy link
Copy Markdown
Collaborator

No description provided.

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