Skip to content

feat(money): add a data service which talks to Money Account API#9278

Open
ffmcgee725 wants to merge 10 commits into
mainfrom
jc/MUSD-1042
Open

feat(money): add a data service which talks to Money Account API#9278
ffmcgee725 wants to merge 10 commits into
mainfrom
jc/MUSD-1042

Conversation

@ffmcgee725

@ffmcgee725 ffmcgee725 commented Jun 26, 2026

Copy link
Copy Markdown
Member

Explanation

The Earn team currently lacks a dedicated data service for fetching user positions, interest accruals, cash-flow history, and vault rate history from the Money Account API (vertical app hosted at money.api.cx.metamask.io).

This PR introduces @metamask/money-account-api-data-service, a new package that:

  • Extends BaseDataService to leverage TanStack Query caching, service policy (retries + circuit-breaking), and messenger integration out of the box.
  • Exposes 4 methods via the messenger: fetchPositions, fetchInterest, fetchHistory, fetchRateHistory.
  • Uses @metamask/superstruct for runtime response validation, with types derived from structs (Infer<typeof ...Struct>) to prevent type/struct drift.
  • Includes detailed validation error messages (superstruct failure details + error cause chain) for easier production debugging.
  • Uses fetchInfiniteQuery for the cursor-paginated history endpoint, giving consumers proper TanStack Query pagination semantics.
  • Configures retryFilterPolicy to skip retrying validation errors (malformed responses won't fix themselves).
  • Supports environment switching (dev / uat / prd) via an Env enum + URL map, following the claims-controller pattern.

This is architected as an independent service. The client calls it directly for API-sourced data, separate from money-account-balance-service which handles RPC-based balance fetching. A future orchestration layer may unify these.

Checklist

  • I've updated the test suite for new or updated code as appropriate
  • I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate
  • I've communicated my changes to consumers by updating changelogs for packages I've changed
  • I've introduced breaking changes in this PR and have prepared draft pull requests for clients and consumer packages to resolve them

Note: No breaking changes introduced — this is an entirely new package (v0.0.0).


Note

Low Risk
New isolated package with no changes to existing controllers; risk is limited to future consumers trusting API-sourced financial display data and external API contract stability.

Overview
Adds @metamask/money-account-api-data-service, a new Earn-team package that fetches vault positions, interest, cash-flow history, and vault rate history from the Money Account HTTP API (separate from RPC-based money-account-balance-service).

MoneyAccountApiDataService extends BaseDataService with TanStack Query caching, messenger actions (fetchPositions, fetchInterest, fetchHistory, fetchRateHistory, invalidateQueries), dev/uat/prd base URLs via Env, and superstruct-validated responses with MoneyAccountApiResponseValidationError (no retries on validation failures). History uses fetchInfiniteQuery for cursor pagination; other endpoints use tuned stale times aligned with server cache TTLs.

Monorepo wiring updates CODEOWNERS, README, teams.json, root tsconfig references, and yarn.lock for the new workspace package.

Reviewed by Cursor Bugbot for commit ae6334b. Bugbot is set up for automated code reviews on this repo. Configure here.

@ffmcgee725 ffmcgee725 requested a review from a team as a code owner June 26, 2026 09:16

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 9c5495a. Configure here.

@ffmcgee725 ffmcgee725 requested a review from Matt561 June 26, 2026 09:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant