Publish watch-only Bitcoin positions into existing Crypto accounts

VL
11d ago
+2077-134

Part 4 of #5620. Stacked on #5672. The public-key layer is already on main via #4615.

up/bitcoin-reading ← up/bitcoin-publishing · Previous discussion #5621 · Fork diff.

Connect a verified wallet preview to the BTC position in an existing Crypto account. Wallet movements change the BTC quantity and record zero-cash trades. A spend of 0.03001000 BTC including its fee reduces the BTC position by that amount and keeps the account's fiat cash intact.

BitcoinWalletAccount#connect! establishes the position and the cash baseline. The wallet processor handles replacements and reorganizations through the shared holding and balance materializers. Manual trades and other assets stay editable. Connected wallets participate in hourly and family syncs.

The provider-connections API exposes sync freshness and aggregate wallet counts to callers who can access the account. Behavioral tests exercise the endpoint and the OpenAPI document includes the new fields.

Validation

The full Rails suite passed on 6d47dc9c0 (18,657 tests, 9 skips). The Chromium suite passed (460 tests). RuboCop, ERB lint, Biome and Brakeman passed.


Summary by cubic

Connects watch-only Bitcoin wallet previews to BTC positions in existing Crypto accounts so wallet movements update the position's quantity without touching fiat cash.

  • Connecting a wallet records zero-cash transfer trades, establishes a cash baseline, and sets the wallet as the sole provider for its account.
  • Wallet reads, replacements, and reorganizations flow through the shared holding and balance materializers, while manual trades and other assets stay editable.
  • Provider-managed BTC trades and holdings reject manual quantity edits, deletions, and security remaps; disconnecting converts the latest quantities to manual holdings.
  • Ledger-to-wallet quantity differences are fixed with zero-cash balance-adjustment trades, which are excluded from goal-deposit matching.
  • Failed or interrupted syncs leave the published journal and its materialization window intact so retries replay the same history, and manual cash reconciliation controls remain available.
  • Cash anchors can coexist with wallet links and keep their provenance after disconnect; position-only links no longer qualify manual cash for automatic FX matching.
  • Hourly and family syncs include connected wallets, and the provider-connections API now returns wallet freshness and aggregate counts for accessible accounts, without keys or addresses.

Validation

  • The full Rails suite (18,657 tests), Chromium suite (460), RuboCop, ERB lint, Biome, and Brakeman all pass.

Summary by CodeRabbit

  • New Features
    • Added Bitcoin wallet connections with wallet status, sync activity, and balance tracking.
    • Bitcoin wallet movements and positions are reflected in account holdings and balances.
    • Added translated labels and guidance for Bitcoin wallet activity and managed positions.
  • Improvements
    • Wallet connection details respect account access and omit sensitive address and key information.
    • Provider-managed positions can’t be edited or deleted, while manual positions remain manageable.
  • Bug Fixes
    • Failed trade deletions now show validation errors instead of failing unexpectedly.

Feedback carried over from earlier PRs

The original comments are linked below, including follow-ups addressed by a later layer.

  • Reviewer suggestion: Preserve goal pledge stamps when refreshing wallet movement metadata. #5621 review · #5622 review
  • Reviewer suggestion: Rebaseline only transactions present in the new snapshot. #5621 review
  • Reviewer suggestion: Exclude wallet quantity reconciliations from goal-deposit matching. #5621 review · #5622 review
  • Reviewer suggestion: Retain the changed date window until account materialization succeeds. #5621 review
  • Reviewer suggestion: Isolate failures while scheduling wallets and continue the legacy import. #5621 review · #5622 review
  • Reviewer suggestion: Load the preceding stored quote for a wallet's first publication. #5621 review
  • Reviewer suggestion: Use an anchor-specific provider-link error when the account has no Bitcoin wallet. #5622 review
  • Reviewer suggestion: Also report balance-adjustment trades in reverse-calculated row components. #5622 review
  • Reviewer suggestion: Preserve cash-anchored history when aggregating it with provider accounts. #5622 review
  • Reviewer suggestion: Continue ordinary account materialization while a linked wallet awaits its first price. #5622 review
  • Reviewer suggestion: Use a single valuation date for the BTC price, holding and external ID. #5622 review
  • Reviewer suggestion: Prefer a newer materialized valuation over an older provider row when appropriate. #5622 review