Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,9 @@ linkStyle default opacity:0.5
message_manager --> base_controller;
message_manager --> controller_utils;
message_manager --> messenger;
money_account_api_data_service --> base_data_service;
money_account_api_data_service --> controller_utils;
money_account_api_data_service --> messenger;
money_account_balance_service --> base_data_service;
money_account_balance_service --> controller_utils;
money_account_balance_service --> messenger;
Expand Down
8 changes: 8 additions & 0 deletions packages/money-account-api-data-service/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- Add `MoneyAccountApiDataService` data service ([#9402](https://github.com/MetaMask/core/pull/9402))
- Fetch user vault positions from the Money Account API (`fetchPositions`)
- Fetch interest earned over a time window (`fetchInterest`)
- Fetch cursor-paginated cash-flow history (`fetchHistory`)
- Fetch vault exchange-rate time series (`fetchRateHistory`)

[Unreleased]: https://github.com/MetaMask/core/
23 changes: 19 additions & 4 deletions packages/money-account-api-data-service/LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
This project is licensed under either of
MIT License

* MIT license ([LICENSE.MIT](LICENSE.MIT))
* Apache License, Version 2.0 ([LICENSE.APACHE2](LICENSE.APACHE2))
Copyright (c) 2026 MetaMask

at your option.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
2 changes: 1 addition & 1 deletion packages/money-account-api-data-service/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# `@metamask/money-account-api-data-service`

Data service for fetching Money account positions, interest, cash-flow history, and vault rate history from the Money Account API
Data service for fetching Money account positions, interest, cash-flow history, and vault rate history from the Money Account API.

## Installation

Expand Down
2 changes: 0 additions & 2 deletions packages/money-account-api-data-service/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@ const baseConfig = require('../../jest.config.packages');
const displayName = path.basename(__dirname);

module.exports = merge(baseConfig, {
// The display name when running multiple projects
displayName,

// An object that configures minimum threshold enforcement for coverage results
coverageThreshold: {
global: {
branches: 100,
Expand Down
11 changes: 10 additions & 1 deletion packages/money-account-api-data-service/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"bugs": {
"url": "https://github.com/MetaMask/core/issues"
},
"license": "(MIT OR Apache-2.0)",
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/MetaMask/core.git"
Expand Down Expand Up @@ -52,12 +52,21 @@
"test:verbose": "NODE_OPTIONS=--experimental-vm-modules jest --verbose",
"test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --watch"
},
"dependencies": {
"@metamask/base-data-service": "^0.1.3",
"@metamask/controller-utils": "^12.3.0",
"@metamask/messenger": "^2.0.0",
"@metamask/superstruct": "^3.1.0",
"@metamask/utils": "^11.11.0",
"@tanstack/query-core": "^4.43.0"
},
"devDependencies": {
"@metamask/auto-changelog": "^6.1.0",
"@ts-bridge/cli": "^0.6.4",
"@types/jest": "^29.5.14",
"deepmerge": "^4.2.2",
"jest": "^29.7.0",
"nock": "^13.3.1",
"ts-jest": "^29.2.5",
"tsx": "^4.20.5",
"typedoc": "^0.25.13",
Expand Down
29 changes: 29 additions & 0 deletions packages/money-account-api-data-service/src/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* Supported environments for the Money Account APY Tracking API.
*/
export enum Env {
DEV = 'dev',
UAT = 'uat',
PRD = 'prd',
}

/**
* Base URL map for the Money Account APY Tracking API, keyed by environment.
*/
export const MONEY_ACCOUNT_API_URL_MAP: Record<Env, string> = {
[Env.DEV]: 'https://money.dev-api.cx.metamask.io',
[Env.UAT]: 'https://money.uat-api.cx.metamask.io',
[Env.PRD]: 'https://money.api.cx.metamask.io',
};

/**
* Default stale time (ms) for position/interest/history queries.
* Matches the server-side cache TTL of 30 seconds.
*/
export const DEFAULT_STALE_TIME_MS = 30_000;

/**
* Default stale time (ms) for rate-history queries.
* Matches the server-side cache TTL of 5 minutes.
*/
export const RATE_HISTORY_STALE_TIME_MS = 300_000;
13 changes: 13 additions & 0 deletions packages/money-account-api-data-service/src/errors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* Thrown when a response from the Money Account API fails superstruct
* validation. Indicates a contract mismatch between client and server.
*/
export class MoneyAccountApiResponseValidationError extends Error {
constructor(message?: string) {
super(
message ??
'MoneyAccountApiDataService: malformed response received from Money Account API',
);
this.name = 'MoneyAccountApiResponseValidationError';
}
}
9 changes: 0 additions & 9 deletions packages/money-account-api-data-service/src/index.test.ts

This file was deleted.

41 changes: 32 additions & 9 deletions packages/money-account-api-data-service/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,32 @@
/**
* Example function that returns a greeting for the given name.
*
* @param name - The name to greet.
* @returns The greeting.
*/
export default function greeter(name: string): string {
return `Hello, ${name}!`;
}
export { MoneyAccountApiDataService } from './money-account-api-data-service';
export type {
MoneyAccountApiDataServiceActions,
MoneyAccountApiDataServiceEvents,
MoneyAccountApiDataServiceMessenger,
} from './money-account-api-data-service';
export type {
MoneyAccountApiDataServiceFetchPositionsAction,
MoneyAccountApiDataServiceFetchInterestAction,
MoneyAccountApiDataServiceFetchHistoryAction,
MoneyAccountApiDataServiceFetchRateHistoryAction,
} from './money-account-api-data-service-method-action-types';
export type {
PositionResponse,
InterestResponse,
HistoryResponse,
RateHistoryResponse,
VaultPosition,
CashFlowEntry,
RateHistoryEntry,
DataFreshness,
CashFlowType,
CashFlowSource,
} from './response.types';
export type {
InterestWindow,
InterestOptions,
HistoryOptions,
RateHistoryOptions,
} from './types';
export { Env } from './constants';
export { MoneyAccountApiResponseValidationError } from './errors';
7 changes: 7 additions & 0 deletions packages/money-account-api-data-service/src/logger.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { createProjectLogger, createModuleLogger } from '@metamask/utils';

export const projectLogger = createProjectLogger(
'money-account-api-data-service',
);

export { createModuleLogger };
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/**
* This file is auto generated.
* Do not edit manually.
*/

import type { MoneyAccountApiDataService } from './money-account-api-data-service';

/**
* Fetches the current vault positions for a given user address.
*
* @param address - The user's Ethereum address.
* @returns The position response containing vault positions.
*/
export type MoneyAccountApiDataServiceFetchPositionsAction = {
type: `MoneyAccountApiDataService:fetchPositions`;
handler: MoneyAccountApiDataService['fetchPositions'];
};

/**
* Fetches the interest earned for a given address and vault over a
* specified time window.
*
* @param address - The user's Ethereum address.
* @param options - Options specifying vault, window, and optional chain ID.
* @returns The interest response.
*/
export type MoneyAccountApiDataServiceFetchInterestAction = {
type: `MoneyAccountApiDataService:fetchInterest`;
handler: MoneyAccountApiDataService['fetchInterest'];
};

/**
* Fetches cursor-paginated cash-flow history for a given address.
* Uses `fetchInfiniteQuery` for proper TanStack Query pagination semantics.
*
* When paginating, consumers must re-pass the same filter options
* (`vaultAddress`, `chainId`, `limit`) alongside `cursor` on every page
* request. This ensures the query key matches the original infinite query
* and that the HTTP request includes the correct filters.
*
* @param address - The user's Ethereum address.
* @param options - Optional filtering and pagination options.
* @returns The history response containing cash-flow entries for the requested page.
*/
export type MoneyAccountApiDataServiceFetchHistoryAction = {
type: `MoneyAccountApiDataService:fetchHistory`;
handler: MoneyAccountApiDataService['fetchHistory'];
};

/**
* Fetches the exchange-rate time series for a given vault.
*
* @param vaultAddress - The vault's Ethereum address.
* @param options - Optional range and chain ID filters.
* @returns The rate history response.
*/
export type MoneyAccountApiDataServiceFetchRateHistoryAction = {
type: `MoneyAccountApiDataService:fetchRateHistory`;
handler: MoneyAccountApiDataService['fetchRateHistory'];
};

/**
* Union of all MoneyAccountApiDataService action types.
*/
export type MoneyAccountApiDataServiceMethodActions =
| MoneyAccountApiDataServiceFetchPositionsAction
| MoneyAccountApiDataServiceFetchInterestAction
| MoneyAccountApiDataServiceFetchHistoryAction
| MoneyAccountApiDataServiceFetchRateHistoryAction;
Loading