Liquidity Docs

Data Model

wallet-api's PostgreSQL schema and the on-chain ERC-3643 / V42 / TokenSettlement contracts it operates.

wallet-api persists a thin projection of on-chain state (the chain is the source of truth) plus its job queue, in PostgreSQL. On-chain, it operates the ERC-3643 backbone, per-user V42 multisig wallets, and the TokenSettlement contract.

PostgreSQL schema

Migrated via goose at boot (pkg/postgres/migrations/00001_init.sql).

TablePurposeKey constraints
onchain_kvGet-or-deploy state: backbone / factory / USDL / settlement addresses, identity recordsk primary key, v jsonb
mpc_walletsOne row per user's wallet (MPC address, V42, executor, guardian, signers, country, profile, tx)user_ref primary key = one wallet per user; indexes on lower(user_address), lower(multisig_address), wallet_id
assetsRegistry of every deployed token (address, name, symbol, decimals, asset_type)id PK = lower(token); idempotent upsert
holdingsCurrent balance per (holder, token)id PK = lower(holder)_lower(token); index on lower(holder)
holding_txnsAppend-only +/- ledger of balance changesid bigserial; indexes on (lower(holder), lower(token), at desc) and tx_hash
jobsDurable async job queueid PK; jobs_claim(lane, status, next_attempt_at) + jobs_reap(status, locked_until)

Race-safety / idempotency is preserved from the prior design:

  • mpc_wallets.user_ref PK + INSERT ... ON CONFLICT DO NOTHING (caller re-reads) = concurrent creation is safe.
  • KV / assets / holdings upserts = INSERT ... ON CONFLICT (id/k) DO UPDATE.
  • Case-insensitive lookups via lower(col) = lower($1).

The order-nonce allocator and settle-record (idempotency by trade_id) are currently in-process (reset on restart). Making them durable in Postgres is a small follow-on.

Connection

One DSN, WALLET_DB_URL (libpq/pgx):

postgres://user:pass@host:5432/wallet_api?sslmode=disable

The service runs postgres.Migrate at boot, so the tables/indexes are created automatically - the database just needs to exist.

On-chain contracts

ContractRole
ERC-3643 backboneIdentityRegistry, ClaimTopicsRegistry, TrustedIssuersRegistry, ModularCompliance - the compliance/identity substrate (deployed once, reused).
StrictSpenderToken / regime tokensThe per-asset ERC-3643 security tokens. Regime-native types (Reg D 506(b)/506(c), Reg S, Reg A, Reg CF, §4(a)(2)) are "born enforcing" their rules.
USDLThe cash-leg stablecoin (minted via POST /deposit).
MultiSigWalletV42 + factoryThe per-user threshold-multisig wallet (the on-chain token holder) and its CREATE2 factory.
TokenSettlementThe dual-intent DvP settlement contract: both sides vouch an OrderIntent; the executor fills matched maker/taker pairs atomically. It also owns the commission (see below).

Fee model (owned by the contract)

The TokenSettlement contract computes and moves the commission. Its _price sets the fee direction from which side is the maker:

  • maker = seller -> fee added on top -> the buyer pays quote + fee.
  • maker = buyer -> fee carved out -> the seller receives bid - fee (seller-paid; the platform default).

wallet-api's role is only to (a) configure the market rate + recipient (setMarket) and (b) route the vouched intents into the correct maker/taker slots; the contract applies the fee.