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).
| Table | Purpose | Key constraints |
|---|---|---|
onchain_kv | Get-or-deploy state: backbone / factory / USDL / settlement addresses, identity records | k primary key, v jsonb |
mpc_wallets | One 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 |
assets | Registry of every deployed token (address, name, symbol, decimals, asset_type) | id PK = lower(token); idempotent upsert |
holdings | Current balance per (holder, token) | id PK = lower(holder)_lower(token); index on lower(holder) |
holding_txns | Append-only +/- ledger of balance changes | id bigserial; indexes on (lower(holder), lower(token), at desc) and tx_hash |
jobs | Durable async job queue | id 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_refPK +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=disableThe service runs postgres.Migrate at boot, so the tables/indexes are created
automatically - the database just needs to exist.
On-chain contracts
| Contract | Role |
|---|---|
| ERC-3643 backbone | IdentityRegistry, ClaimTopicsRegistry, TrustedIssuersRegistry, ModularCompliance - the compliance/identity substrate (deployed once, reused). |
| StrictSpenderToken / regime tokens | The 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. |
| USDL | The cash-leg stablecoin (minted via POST /deposit). |
| MultiSigWalletV42 + factory | The per-user threshold-multisig wallet (the on-chain token holder) and its CREATE2 factory. |
| TokenSettlement | The 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.
Components
Every internal package of wallet-api in detail: onchain, multisig, trading, walletapi, the HTTP APIs, the durable job queue, and the MPC layer.
Workflows
Everything wallet-api does: MPC wallet provisioning, ERC-3643 identity onboarding, asset lifecycle, dual-intent trade & settlement, and the MPC ceremony.