Liquidity Docs

Components

Every internal package of wallet-api in detail: onchain, multisig, trading, walletapi, the HTTP APIs, the durable job queue, and the MPC layer.

wallet-api is a single Go binary composed of internal packages behind clean interfaces. This is what each one does.

On-chain core

PackageRole
internal/onchainThe ERC-3643 / T-REX deployer + identity + venue-gate backbone. Self-deploys the shared infra (backbone, factory, USDL, TokenSettlement) lazily via get-or-deploy, and owns EnsureVerified (ONCHAINID + IdentityRegistry), chain reads, and the KV state.
internal/multisigThe V42 threshold-multisig wallet factory flow. CreateWallet deploys a per-user V42 clone around the user's MPC address, provisions its executor + guardian, funds it for gas, and (strict guard) verifies the signer's identity first.
internal/tradingAsset lifecycle (create / mint / burn / freeze / forced-transfer / transfer), the dual-intent propose + settle trade path, chain-read views, and the pluggable stores (asset registry, holdings, country/wallet lookup, order-nonce, settle-record).

HTTP surfaces

PackageEndpoints
internal/walletapiWallet provisioning (POST /wallet), server-side sign, and the MPC relays: GET /wallet/mpc-config plus the WebSockets /wallet/mpc/relay (keygen) and /wallet/mpc/sign (signing). Both sockets are mounted by RegisterWS outside the request-timeout group - the timeout wrapper breaks the Hijack an upgrade needs, and a ceremony outlives any request timeout.
internal/assetapiAsset create/mint/burn/accredit, deposit (USDL), issuer ops (freeze / forced-transfer / transfer), identity register/deregister/verify, and the balance/frozen reads.
internal/tradeapiPOST /trade/propose + /trade/propose-tx (build the unsigned vouch), /trade/cancel-tx, POST /settlement/settle (+ status by trade_id), GET /contracts, and the standing-allowance approve flow.
internal/chainapiGeneric chain reads for consumers: GET /chain/head, /chain/block/{n}/hash, POST /chain/logs, GET /chain/tx/{hash}/receipt.
internal/rawcallapiPer-role raw-call escape hatches: POST /wallets/{wallet}/{user,executor,guardian,read}-call, POST /settlement/{admin,executor,user,read}-call, POST /regimes/{admin,read}-call, and GET /capabilities (the signer-lane boundary map). The caller ABI-encodes the calldata; this surface enforces which key signs, the submit/wait semantics, and an optional exact-selector allowlist. Synchronous, and must sit behind auth.

Durable job queue

internal/jobs - a Postgres-backed durable queue. Write endpoints enqueue and return 202 { job_id }; workers execute, retry with backoff, dead-letter, reap crashed leases, and POST the result to callback_url.

  • Lanes: admin (concurrency 1 - the ta-admin nonce is serial) and user (parallel across wallets).
  • Lease: atomic claim of the oldest runnable job in a lane via UPDATE ... WHERE id = (SELECT ... FOR UPDATE SKIP LOCKED LIMIT 1).
  • Reap: jobs whose locked_until has passed (a crashed worker) return to pending.

MPC & signing layer

File / packageRole
pkg/mpc/signer.go · hashsigner.goThe signer seam: Signer / HashSigner interfaces every caller depends on, so the backing key store swaps without touching business logic.
pkg/mpc/devsigner.go · devkeygen.goDev-only in-process keys, clearly labelled and never valid in production config.
pkg/mpc/httpsigner.goGeneric HTTP signing backend.
pkg/mpc/hub.go · keygen.go · mpciumsigner.goEngine mode: MpciumHub (one result subscription per process, fanned out by WalletID / TxID), MpciumKeygen (DKG + authorizer-signature gate), MpciumSigner.
pkg/mpc/hsmsigner.go · hsmgen.goThe HSM keystore seam for platform keys: digest-mode POST /sign by label id, and POST /generate-address?curve=secp256k1 to provision per-wallet executor keys (persist the returned label).
pkg/mpc/node3token.goMints the short-lived HS256 token that authorizes one party against node3.
internal/walletapi/relay.goThe node3 relay: dials node3 before upgrading the device socket (so a dial failure is a clean HTTP error), strips the caller's own token/api_key, injects the node3 credential, and pipes frames both ways without decoding them.

See mpc for how these fit together at runtime.

Platform & infra packages

PackageRole
pkg/postgresPool(ctx, url) (pgxpool) + Migrate(ctx, url) (goose over embedded //go:embed migrations/*.sql).
pkg/configTyped WALLET_* env config with dev defaults.
pkg/chaingo-ethereum client helpers (dial, reads, receipts).
pkg/substrateThe substrate gas-sponsor client (sponsor mode - the sponsor pays user trade gas so the user wallet can hold zero).
pkg/observabilityslog JSON logging + Prometheus metrics.

Store interfaces (why swapping the DB was clean)

The business logic depends only on interfaces, implemented once against Postgres: onchain.KV, walletapi.WalletStore + SignerResolver, trading.{AssetRegistry, HoldingsStore, CountryLookup, WalletLookup, ExecutorResolver}, and jobs.Enqueuer. Replacing the persistence layer (Mongo -> Postgres) touched only the implementations and boot wiring, not the domain code.