lez-programs/apps/amm/flake.nix

163 lines
6.0 KiB
Nix
Raw Normal View History

{
feat(amm): wire the AMM app to the LEZ wallet module Turns the dummy-data AMM UI into a real client of the on-chain LEZ wallet. Adds a hand-written ui_qml C++ backend (src/AmmUi*) over the core logos_execution_zone module: create/open a local wallet, create and list public/private accounts, and a navbar Connect / Connected + account-selector + Disconnect flow. Onboarding is password-only (no path picking) with a per-app wallet at ~/.lee/amm-wallet (override: AMM_WALLET_HOME_DIR); standalone gets its own wallet, Basecamp shares accounts via adopt-on-start. Requires Nix with flakes; macOS also needs `sandbox = false` (the default). The logos_execution_zone input is pinned to a module rev whose LEZ (lssa) already includes the macOS Metal-build fix, so no `--override-input` is needed — plain `nix run .` works: cd apps/amm nix run . - create_new now returns the new wallet's BIP39 mnemonic (not an int status); the app currently discards it, so the wallet can't yet be recovered. Surfacing it in onboarding (+ restore_storage) is a follow-up. - The wallet password is currently a no-op upstream (storage.rs: "TODO: use password for storage encryption"); storage.json is plaintext. So Disconnect is a UI-level lock and reconnect does not (cannot yet) re-prompt for it. - wallet-ffi requires explicit config/storage paths; a *_default() FFI would let the app drop its path handling. - Bundled network config: connects to whatever WalletConfig::default() points at; real testnet endpoints still TBD.
2026-06-24 14:50:17 +02:00
description = "Logos AMM QML UI trade and provide liquidity on the LEZ AMM";
inputs = {
logos-module-builder.url = "github:logos-co/logos-module-builder";
nixpkgs.url = "github:NixOS/nixpkgs/nixos-25.11-small";
crane.url = "github:ipetkov/crane/v0.23.4";
feat(amm): wire the AMM app to the LEZ wallet module Turns the dummy-data AMM UI into a real client of the on-chain LEZ wallet. Adds a hand-written ui_qml C++ backend (src/AmmUi*) over the core logos_execution_zone module: create/open a local wallet, create and list public/private accounts, and a navbar Connect / Connected + account-selector + Disconnect flow. Onboarding is password-only (no path picking) with a per-app wallet at ~/.lee/amm-wallet (override: AMM_WALLET_HOME_DIR); standalone gets its own wallet, Basecamp shares accounts via adopt-on-start. Requires Nix with flakes; macOS also needs `sandbox = false` (the default). The logos_execution_zone input is pinned to a module rev whose LEZ (lssa) already includes the macOS Metal-build fix, so no `--override-input` is needed — plain `nix run .` works: cd apps/amm nix run . - create_new now returns the new wallet's BIP39 mnemonic (not an int status); the app currently discards it, so the wallet can't yet be recovered. Surfacing it in onboarding (+ restore_storage) is a follow-up. - The wallet password is currently a no-op upstream (storage.rs: "TODO: use password for storage encryption"); storage.json is plaintext. So Disconnect is a UI-level lock and reconnect does not (cannot yet) re-prompt for it. - wallet-ffi requires explicit config/storage paths; a *_default() FFI would let the app drop its path handling. - Bundled network config: connects to whatever WalletConfig::default() points at; real testnet endpoints still TBD.
2026-06-24 14:50:17 +02:00
# Core wallet module (the LEZ wallet FFI Qt plugin). The input name must
# match the metadata.json `dependencies` entry so the builder can resolve
# it as a module dependency. Public testnet still exposes the v0.2.0-rc6
# wallet RPC contract.
logos_execution_zone = {
url = "github:logos-blockchain/logos-execution-zone-module?rev=d70225ced646934d2294fd9e8f8b03615c104b80";
inputs.logos-execution-zone.url =
"github:logos-blockchain/logos-execution-zone?rev=e37876a64028a335eb693198a1ed6a0e875ec5b4";
};
};
outputs = inputs@{
logos-module-builder,
logos_execution_zone,
nixpkgs,
crane,
...
}:
let
# Preserve the macOS Metal workaround without moving the wallet past the
# RPC contract currently deployed on public testnet. Crane builds the
# dependency artifacts separately, so both derivations need the setting.
withXcrunNoCache = package:
package.overrideAttrs (previous:
{
xcrun_nocache = "1";
}
// (if previous ? cargoArtifacts && previous.cargoArtifacts ? overrideAttrs
then {
cargoArtifacts = previous.cargoArtifacts.overrideAttrs (_: {
xcrun_nocache = "1";
});
}
else { }));
executionZone = logos_execution_zone.inputs.logos-execution-zone;
testnetExecutionZone = executionZone // {
packages = builtins.mapAttrs
(system: packages:
if builtins.match ".*-darwin" system == null then packages
else
let
wallet = withXcrunNoCache packages.wallet;
in
packages // {
inherit wallet;
default = wallet;
})
executionZone.packages;
};
# Evaluate the pinned module source with the testnet-compatible wallet.
# This is ordinary flake composition, not a relative flake input, keeping
# Nix 2.25 lock and build behavior portable.
logosExecutionZoneModule =
(import "${logos_execution_zone.outPath}/flake.nix").outputs {
logos-module-builder = logos_execution_zone.inputs.logos-module-builder;
logos-execution-zone = testnetExecutionZone;
nix-bundle-lgx = logos_execution_zone.inputs.nix-bundle-lgx;
};
# Name must match metadata.json so the builder resolves the core module.
moduleInputs = inputs // {
logos_execution_zone = logosExecutionZoneModule;
};
ammClientInput = (import ../../flake.nix).outputs {
inherit nixpkgs crane;
};
moduleBuild = logos-module-builder.lib.mkLogosQmlModule {
src = ./.;
configFile = ./metadata.json;
flakeInputs = moduleInputs;
preConfigure = ''
cmakeFlagsArray+=("-DLOGOS_WALLET_SOURCE_DIR=${../shared/wallet}")
'';
externalLibInputs = {
amm_client = ammClientInput;
};
postInstall = ''
# The builder installs the view under lib/qml after this hook. Its
# import descriptor points back to this compiled shared QML module.
test -f ${./qml}/Logos/Wallet/qmldir
walletQmlDir="shared-wallet/qml/Logos/Wallet"
if [ ! -d "$walletQmlDir" ]; then
echo "Built Logos.Wallet QML module not found"
exit 1
fi
walletQmlInstallDir="$out/lib/Logos/Wallet"
mkdir -p "$walletQmlInstallDir"
cp -r "$walletQmlDir/." "$walletQmlInstallDir/"
test -f "$walletQmlInstallDir/qmldir"
'';
};
publicApps = logos-module-builder.lib.common.forAllSystems nixpkgs ({ system, pkgs }:
{
default = logos-module-builder.lib.mkStandaloneApp {
inherit pkgs;
standalone =
logos-module-builder.inputs.logos-standalone-app.packages.${system}.default;
plugin = moduleBuild.packages.${system}.default;
metadataFile = ./metadata.json;
# The qt-plugin layout only copies the plugin and replica factory.
# Keep the complete lib tree so sibling external libraries such as
# libamm_client remain available through the plugin's loader path.
format = "qml";
moduleDeps =
logos-module-builder.lib.common.collectAllModuleDeps
system moduleInputs moduleBuild.config.dependencies;
};
}
);
publicPackages = builtins.mapAttrs
(system: packages: packages // {
logos_execution_zone-lgx =
logosExecutionZoneModule.packages.${system}.lgx;
logos_execution_zone-lgx-portable =
logosExecutionZoneModule.packages.${system}.lgx-portable;
})
moduleBuild.packages;
linuxChecks =
let
pkgs = nixpkgs.legacyPackages.x86_64-linux;
walletModule = logosExecutionZoneModule.packages.x86_64-linux.lib;
in
{
wallet-rpc-contract = pkgs.runCommand "amm-wallet-rpc-contract" { } ''
wallet="${walletModule}/lib/libwallet_ffi.so"
test -f "$wallet"
${pkgs.binutils}/bin/strings "$wallet" > methods
${pkgs.gnugrep}/bin/grep -Fq sendTransaction methods
${pkgs.gnugrep}/bin/grep -Fq getProofForCommitment methods
if ${pkgs.gnugrep}/bin/grep -Fq getProofsAndRoot methods; then
echo "wallet uses unsupported testnet RPC method getProofsAndRoot"
exit 1
fi
touch "$out"
'';
};
in
moduleBuild // {
apps = publicApps;
packages = publicPackages;
checks = (moduleBuild.checks or { }) // {
x86_64-linux = (moduleBuild.checks.x86_64-linux or { }) // linuxChecks;
};
};
}