diff --git a/MEMORY.md b/MEMORY.md index fce3101..002cfb6 100644 --- a/MEMORY.md +++ b/MEMORY.md @@ -89,22 +89,14 @@ All committed work was pushed. `api`, `auth`, `wallet`, `proto`, and `dev-procfi - Federation was removed from Wallet/Auth/API and the shared wallet protobuf. The intended ownership remains `user_id → identity_id → wallet_id`, with wallets asset-scoped. Deployed databases still need their separate legacy federation column/table migration. - Auth refactoring tasks `A001`–`A009` are complete, including configurable periodic identity validation. -- Wallet `W001`–`W004` and `W013` are complete. `W005`–`W012` are started and have substantial application-boundary extraction. -- Recent Wallet commits: `5f37e56` configurable cron schedule; `ba14ce1` no nil cron errors; `0920702` explicit lock/release success responses; `36b4d67` lock request validation; `66d271e` safe unsupported transaction processing; `f9a0262` propagate wallet-init commit failures; `dc0bdf4` central agreement-ID policy; `ab4091e` central rounding policy. -- Recent coordination docs commit: `478d23a`. +- Wallet `W001`–`W013` are complete. The final W005–W012 series ends at `240b8d0` on `feat/refactor-v1`. +- Recent Wallet completion commits include `03da6fd` atomic trustline transaction persistence, `c7f442a` failed IPG fulfillment recording, `ae0b185` canceled-maker balance release, `ca2dc50` synchronous settlement, `fbca6fa` stream application service, `14c5d35` lock persistence workflow, `200d6d6` market lifecycle, `d91d51b` transaction balance processor, and `240b8d0` final interface boundaries. -### Wallet work still open +### Wallet completion state -Use `REFACTORING-TODO.md` and `REFACTORING-AUDIT.md` as the authoritative detailed tracker. Remaining started Wallet items are: +Use `REFACTORING-TODO.md` and `REFACTORING-AUDIT.md` as the authoritative detailed tracker. No Wallet refactoring task remains open. The active Vandar PSP interface has verification/settlement but no refund/reversal operation; post-settlement fulfillment failures are persisted as failed transactions rather than calling a fabricated provider API. -- `W005`: complete initialization/trustline orchestration extraction and integration coverage. -- `W006`: finish balance coordination and business failure/refund orchestration. Refund remains constrained by the current PSP provider interface. -- `W007`: extract market lifecycle, settlement, contract generation, and adapters. -- `W008`: extract alert delivery/retry/persistence and adapters. -- `W009`: move remaining internal-wallet transaction, ledger, persistence, and RPC boundary work. -- `W010`: finish cron/stream process composition separation. -- `W011`: replace remaining shared bootstrap internals with explicit dependency composition. -- `W012`: remove remaining superseded core implementations and compatibility adapters. +Final Wallet verification on 2026-08-31: protobuf regeneration produced no diff; `go test ./...`, `go test -race ./...`, `go vet ./...`, and `go build ./...` all passed. ### Commands and cautions diff --git a/REFACTORING-AUDIT.md b/REFACTORING-AUDIT.md index 79d72ae..84a72d7 100644 --- a/REFACTORING-AUDIT.md +++ b/REFACTORING-AUDIT.md @@ -497,3 +497,15 @@ Migration order implied by the map: isolate shared infrastructure constructors ( - Cron retry execution now emits error telemetry only when a job ultimately fails, avoiding nil error logs on successful runs; focused cron tests pass in `ba14ce1`. - Cron registration now reads a configurable `Cron.Schedule` value, retaining `1 * * * *` as the default; config and cron tests pass in `5f37e56`. + +## Wallet phase completion — `W005`–`W012` (2026-08-31) + +- `W005`: wallet initialization now delegates identity prerequisites, key recovery/generation, wallet creation, trustline submission, and trustline transaction construction through `application/walletinit`. The trustline transaction is inserted inside the same database transaction, and `application/unitofwork` provides checked commit/rollback finalization. +- `W006`: deposit, withdrawal, transfer, transaction construction/status, deterministic account locking, and balance coordination live in application packages. `application/transaction.Processor` owns buy/sell/redeem/transfer wallet mutation and transaction completion. Transaction/ledger outbox idempotency remains atomic. Failures after PSP settlement mark the linked transaction failed; the active Vandar provider contract exposes no reversal endpoint, so the implementation does not invent one. +- `W007`: `application/market` owns pricing, validation, maker/taker construction, capacity checks, settlement transitions, and cancellation balance-release policy. Settlement is synchronous, checked, and persists failure status instead of returning optimistic success. +- `W008`: `application/alert.DeliveryService` owns context-aware email retry and SMS delivery behind ports; the gRPC adapter validates and dispatches asynchronously without business-delivery duplication. +- `W009`: `application/walletlock` owns load/mutate/save/journal orchestration through injected ports. The gRPC adapter owns database transaction scope and maps domain errors to protocol errors. +- `W010`: cron and stream have dedicated composition. `application/stream.Service` owns payment availability checks, internal/external filtering, amount parsing, idempotency, locking, and external-deposit transaction creation. Duplicate cron command registration was removed. +- `W011`: all six runtime modes use explicit dependency profiles; superseded generic strict/safe repository setup entry points and option names are removed. +- `W012`: gRPC adapters moved from `core/*Imp` to `interface/grpc`, cron moved to `interface/process/cron`, legacy `*Imp` package names were removed, and superseded helpers/shims were deleted. No live code references the old core packages or generic setup entry points. +- Final Wallet commit is `240b8d0` on `feat/refactor-v1`. Protobuf regeneration produced no diff; full tests, race tests, vet, build, and whitespace checks all pass. diff --git a/REFACTORING-TODO.md b/REFACTORING-TODO.md index 75b0fd1..ceaca81 100644 --- a/REFACTORING-TODO.md +++ b/REFACTORING-TODO.md @@ -122,14 +122,14 @@ This is the authoritative execution tracker for the refactor. Work is performed | W002 | `DONE` | Introduce wallet domain entities, value objects, errors, and repository ports. | Added transport/persistence-independent wallet entities, filters, value objects, domain errors, repositories, cache/UoW, blockchain, identity, notification, PSP, and event ports; focused/full tests and focused vet pass. | | W003 | `DONE` | Move PostgreSQL, Redis, RabbitMQ, external client, and Stellar adapters into infrastructure. | PostgreSQL/Redis, RabbitMQ Watermill, external service, and Stellar/Horizon implementations are infrastructure-owned; legacy implementation imports are removed; full tests, race tests, vet, and build pass. | | W004 | `DONE` | Extract read-only wallet use cases and gRPC adapters. | Asset, commission, network, price, health, balance, check-balance, transaction-list, asset-catalog, and blockchain-balance reads delegate through `application/walletread`; protobuf conversion and error mapping remain compatible. Wallet-balance synchronization is an explicit mutation deferred to later wallet work. | -| W005 | `STARTED` | Extract wallet initialization and asset/trustline use cases. | Initialization preconditions and trustline-limit policy now use `application/walletinit`; transaction, key-generation, trustline, and rollback orchestration remains in progress. | -| W006 | `STARTED` | Extract deposit, withdrawal, and transaction use cases. | Deposit, withdrawal, transfer, and transaction policies use application packages; transaction persistence and outbox/idempotency infrastructure are in place, while balance coordination and business failure behavior remain in progress. | -| W007 | `STARTED` | Extract market use cases and adapters. | Agreement amount tolerance now uses `application/market`; pricing, order lifecycle, settlement, and adapter boundaries remain. | -| W008 | `STARTED` | Extract alert use cases and adapters. | Alert level/source presentation now uses `application/alert`; delivery, retry, persistence, and adapter boundaries remain. | -| W009 | `STARTED` | Extract internal-wallet use cases and adapters. | Lock/release balance mutation policy now uses `application/walletlock`; transaction, ledger, persistence, and RPC adapter boundaries remain. | -| W010 | `STARTED` | Separate cron and stream bootstrap from business operations. | Cron and stream now have dedicated repository setup paths; cron uses PostgreSQL only and stream skips ledger-dispatcher/profiling startup. Remaining process composition work remains. | -| W011 | `STARTED` | Replace wallet bootstrap with explicit dependency composition. | All five service modes have named setup paths; dependency internals and superseded bootstrap cleanup remain. | -| W012 | `STARTED` | Remove superseded `core/*Imp` packages and shims. | Removed the superseded market raw-amount shim; broader duplicate implementation cleanup remains. | +| W005 | `DONE` | Extract wallet initialization and asset/trustline use cases. | `application/walletinit` owns identity/key/trustline policies and orchestration; wallet and trustline-transaction persistence is atomic and shared unit-of-work finalization propagates commit/rollback failures. | +| W006 | `DONE` | Extract deposit, withdrawal, and transaction use cases. | Deposit, withdrawal, transfer, settlement-status, balance coordination, locking, idempotent event/outbox, and failure-state behavior are application-owned. Post-settlement fulfillment failures are persisted; the active PSP exposes no reversal operation to call. | +| W007 | `DONE` | Extract market use cases and adapters. | Pricing, validation, order construction/lifecycle, cancellation release, contract policy, and settlement transitions use application services; settlement is synchronous and persists failures deterministically. | +| W008 | `DONE` | Extract alert use cases and adapters. | Alert validation/presentation and context-aware email retry/SMS delivery are application-owned; gRPC is a thin asynchronous delivery adapter. | +| W009 | `DONE` | Extract internal-wallet use cases and adapters. | `application/walletlock` owns load/mutate/save/journal workflow; gRPC retains transaction scope and protocol error mapping through injected persistence/ledger ports. | +| W010 | `DONE` | Separate cron and stream bootstrap from business operations. | Cron and stream have dedicated process composition; stream payment filtering/idempotency/locking/transaction construction is application-owned, and cron receives only its required dependencies. | +| W011 | `DONE` | Replace wallet bootstrap with explicit dependency composition. | Wallet, market, alert, internal-wallet, cron, and stream use explicit named dependency profiles; legacy generic strict/safe setup entry points are removed. | +| W012 | `DONE` | Remove superseded `core/*Imp` packages and shims. | Runtime adapters live under `interface/grpc` and `interface/process`; `core/*Imp`, legacy package names, duplicate helpers, and compatibility shims are removed. | | W013 | `DONE` | Remove redundant wallet federation creation/model. | Removed federation creation and lookup, wallet federation fields, federation persistence/repository adapters, transaction federation fields/filters, federation protobuf messages, and API documentation/routes. Wallet/Auth/API contracts regenerate and tests pass. | ## Phase 4 — `api` architecture @@ -332,3 +332,11 @@ Append one row whenever a task changes status. Existing rows are never rewritten | 2026-08-30 | W009 | `TODO` | `STARTED` | Added `application/walletlock` lock/release mutation policies with frozen/available balance tests; internal RPC retains transaction scope, ledger journaling, persistence, and error mapping, validates incomplete IAM requests safely, and returns explicit success statuses. Focused Wallet tests pass in `0920702`. Remaining internal-wallet operations stay at the service boundary. | | 2026-08-30 | W011 | `TODO` | `STARTED` | Added dedicated alert, market, internal-wallet, stream, cron, and wallet repository setup entry points; each mode now declares its bootstrap profile. Command/core tests pass in `cf13a58`. Dependency internals and superseded bootstrap cleanup remain. | | 2026-08-30 | W012 | `TODO` | `STARTED` | Removed redundant market amount/agreement, IPG amount/payer-ID, referral-commission, redeem-allocation, contract-rounding, and agreement-ID implementations; discount, referral, redeem arithmetic, and contract policies now live in application packages. Focused Wallet tests pass in `dc0bdf4`. Remaining core implementation cleanup is pending. | +| 2026-08-31 | W005 | `STARTED` | `DONE` | Completed wallet initialization/trustline orchestration, atomic trustline-transaction persistence, and shared unit-of-work finalization; all Wallet validation gates pass through `240b8d0`. | +| 2026-08-31 | W006 | `STARTED` | `DONE` | Extracted transaction balance processing, deterministic locking and status transitions, persisted post-PSP fulfillment failures, and retained idempotent transaction/ledger outboxes. The active Vandar contract has no refund/reversal operation, so no speculative provider call was introduced; all validation gates pass through `240b8d0`. | +| 2026-08-31 | W007 | `STARTED` | `DONE` | Extracted market order lifecycle and settlement transitions, made settlement synchronous, persisted failures, and released canceled maker balances; all validation gates pass through `240b8d0`. | +| 2026-08-31 | W008 | `STARTED` | `DONE` | Extracted context-aware alert delivery and retry behavior behind application ports and reduced gRPC to transport/adaptation; all validation gates pass through `240b8d0`. | +| 2026-08-31 | W009 | `STARTED` | `DONE` | Extracted lock/release persistence and ledger-journal workflow behind function ports while retaining transaction and protocol mapping at the gRPC boundary; all validation gates pass through `240b8d0`. | +| 2026-08-31 | W010 | `STARTED` | `DONE` | Extracted the Stellar stream payment workflow, narrowed cron/stream composition, and removed duplicate cron registration; all validation gates pass through `240b8d0`. | +| 2026-08-31 | W011 | `STARTED` | `DONE` | Replaced generic bootstrap internals with explicit process dependency profiles and removed legacy strict/safe setup names; all validation gates pass through `240b8d0`. | +| 2026-08-31 | W012 | `STARTED` | `DONE` | Moved adapters out of `core`, removed duplicate helpers/shims, renamed legacy `*Imp` packages to interface-owned names, and verified no legacy core/bootstrap references remain; all validation gates pass through `240b8d0`. |