factor(amm-ui): source new-position network context from AMM_PROGRAM_BIN/TOKENS_CONFIG/wallet

The create-pool / new-position flow carried its own network layer:
AMM_UI_NETWORK + AMM_UI_DEVNET_FILE (a devnet.json) or a bundled
config/networks.json supplied the AMM program id and token set, and a
JSON-RPC channel/checkpoint "identity probe" gated the flow to a verified
network. Main already exposes all of this the way the Swap view consumes it,
so collapse onto those sources instead of a parallel system:

- ammProgramId  <- $AMM_PROGRAM_BIN (derived like swapExactInput's program id;
                   doubles as the quote's network fingerprint so a quote can't
                   be replayed against a different deployment)
- tokenIds      <- $TOKENS_CONFIG (amm-tokens.json), same as the Swap picker
- sequencer     <- the wallet config (already surfaced via syncWalletState)

networkSnapshot() builds the ActiveNetworkSnapshot from those; status is
"ready"/"config_missing", gated to "loading" until wallet state resolves so no
module reads happen during construction. The channel probe is gone — submit
needs no channelId (the wallet module supplies the channel via
submitPublicTransaction), so the whole verification apparatus was overhead.

Removes: AMM_UI_NETWORK / AMM_UI_DEVNET_FILE, devnet.json / networks.json, the
ActiveNetwork class (+ its test) and its QNetwork channel probe, and Qt6Network.
ActiveNetwork.h keeps only the ActiveNetworkSnapshot struct. Run command drops
the AMM_UI_* vars:
```
  LEE_WALLET_HOME_DIR=… AMM_PROGRAM_BIN=… TOKENS_CONFIG=… nix run .#amm-ui
```
This commit is contained in:
r4bbit
2026-07-27 12:14:27 +02:00
parent d7017a2515
commit e585489a60
8 changed files with 85 additions and 386 deletions
-65
View File
@@ -1,65 +0,0 @@
#include "ActiveNetwork.h"
#include <QJsonArray>
#include <QJsonDocument>
#include <QJsonObject>
#include <QTemporaryFile>
namespace {
bool expect(bool condition, const char* message)
{
if (!condition)
qCritical("%s", message);
return condition;
}
}
int main()
{
const QString identity(64, QLatin1Char('a'));
const QString programId(64, QLatin1Char('b'));
const QString tokenId(64, QLatin1Char('c'));
QTemporaryFile config;
if (!config.open())
return 1;
config.write(QJsonDocument(QJsonObject {
{ QStringLiteral("channelId"), identity },
{ QStringLiteral("ammProgramId"), programId },
{ QStringLiteral("tokenDefinitionIds"), QJsonArray { tokenId } },
}).toJson(QJsonDocument::Compact));
config.flush();
qputenv("AMM_UI_NETWORK", "devnet");
qputenv("AMM_UI_DEVNET_FILE", config.fileName().toLocal8Bit());
ActiveNetwork network;
if (!expect(network.load(), "devnet config should load"))
return 1;
if (!expect(network.snapshot().status == QStringLiteral("network_unknown"),
"loaded network should await identity"))
return 1;
network.sequencerChanged(true);
network.finishIdentityProbe(QString(64, QLatin1Char('d')));
if (!expect(network.status() == QStringLiteral("network_mismatch"),
"wrong identity should block the network"))
return 1;
network.reachabilityChanged(false, true);
network.reachabilityChanged(true, false);
network.finishIdentityProbe(identity);
const ActiveNetworkSnapshot snapshot = network.snapshot();
if (!expect(snapshot.status == QStringLiteral("ready"),
"matching identity should ready the network"))
return 1;
if (!expect(snapshot.fingerprint == QStringLiteral("channel:") + identity,
"devnet fingerprint should use channel identity"))
return 1;
if (!expect(snapshot.ammProgramId == programId
&& snapshot.tokenIds == QStringList { tokenId },
"network snapshot should preserve configured program and tokens"))
return 1;
return 0;
}