-
-
Notifications
You must be signed in to change notification settings - Fork 274
feat: MUSD-248 create money-account-balance-service #8428
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Matt561
merged 21 commits into
main
from
feat/musd-248-create-money-account-balance-service
Apr 14, 2026
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
a4d4dda
feat: first iteration of the money-account-balance-service
Matt561 7727e88
feat: money-account-balance-service cleanup
Matt561 aa31fa3
feat: update yarn.lock
Matt561 24d7d65
feat: made all VaultApyResponse fields optional except for apy and ti…
Matt561 6e596eb
feat: add tests
Matt561 e755f69
chore: updated README
Matt561 4d99a0b
feat: cleanup
Matt561 328e9a4
feat: added optional staleTime param to getExchangeRate to allow impe…
Matt561 61acc24
feat: broke out money-account-balance-service into its own package
Matt561 9b51e57
feat: reverted changes to packages/money-account-controller/package.json
Matt561 6ac2e84
Merge branch 'main' into feat/musd-248-create-money-account-balance-s…
Matt561 e21594d
feat: updated yarn.lock
Matt561 2932799
feat: resolved incorrect @metamask/auto-changelog version used money-…
Matt561 c05c5fb
feat: updated readme
Matt561 0bd238d
feat: fixed formatting issues in package.json
Matt561 146f004
feat: updated money-account-balance-service changelog
Matt561 cc71b5c
feat: generated method-action-types
Matt561 b8b1a3a
feat: resolving cursor bug bot comments
Matt561 30334d6
feat: updated money-account-balance-service codeowner to earn team
Matt561 142edb6
Merge branch 'main' into feat/musd-248-create-money-account-balance-s…
Matt561 2deb59b
feat: changes based on core-platform review
Matt561 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| # Changelog | ||
|
|
||
| All notable changes to this project will be documented in this file. | ||
|
|
||
| The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), | ||
| and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). | ||
|
|
||
| ## [Unreleased] | ||
|
|
||
| ### Added | ||
|
|
||
| - Add `MoneyAccountBalanceService` data service ([#8428](https://github.com/MetaMask/core/pull/8428)) | ||
| - Fetch mUSD ERC-20 balance via RPC (`getMusdBalance`) | ||
| - Fetch musdSHFvd vault share balance via RPC (`getMusdSHFvdBalance`) | ||
| - Fetch Veda Accountant exchange rate via RPC (`getExchangeRate`) | ||
| - Compute mUSD-equivalent value of vault share holdings (`getMusdEquivalentValue`) | ||
| - Fetch vault APY from the Veda performance REST API (`getVaultApy`) | ||
|
|
||
| [Unreleased]: https://github.com/MetaMask/core/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| MIT License | ||
|
|
||
| Copyright (c) 2026 MetaMask | ||
|
|
||
| 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| # `@metamask/money-account-balance-service` | ||
|
|
||
| Data service for fetching Money account balances via on-chain RPC reads, the Veda Accountant exchange rate, and the Veda vault APY from Veda's REST API. | ||
|
|
||
| ## Installation | ||
|
|
||
| `yarn add @metamask/money-account-balance-service` | ||
|
|
||
| or | ||
|
|
||
| `npm install @metamask/money-account-balance-service` | ||
|
|
||
| ## Contributing | ||
|
|
||
| This package is part of a monorepo. Instructions for contributing can be found in the [monorepo README](https://github.com/MetaMask/core/blob/main/README.md). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| /* | ||
| * For a detailed explanation regarding each configuration property and type check, visit: | ||
| * https://jestjs.io/docs/configuration | ||
| */ | ||
|
|
||
| const merge = require('deepmerge'); | ||
| const path = require('path'); | ||
|
|
||
| const baseConfig = require('../../jest.config.packages'); | ||
|
|
||
| const displayName = path.basename(__dirname); | ||
|
|
||
| module.exports = merge(baseConfig, { | ||
| displayName, | ||
|
|
||
| coverageThreshold: { | ||
| global: { | ||
| branches: 100, | ||
| functions: 100, | ||
| lines: 100, | ||
| statements: 100, | ||
| }, | ||
| }, | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| { | ||
| "name": "@metamask/money-account-balance-service", | ||
| "version": "0.0.0", | ||
| "description": "Data service for fetching Money account balances, exchange rates, and vault APY", | ||
| "keywords": [ | ||
| "Ethereum", | ||
| "MetaMask" | ||
| ], | ||
| "homepage": "https://github.com/MetaMask/core/tree/main/packages/money-account-balance-service#readme", | ||
| "bugs": { | ||
| "url": "https://github.com/MetaMask/core/issues" | ||
| }, | ||
| "license": "MIT", | ||
| "repository": { | ||
| "type": "git", | ||
| "url": "https://github.com/MetaMask/core.git" | ||
| }, | ||
| "files": [ | ||
| "dist/" | ||
| ], | ||
| "sideEffects": false, | ||
| "main": "./dist/index.cjs", | ||
| "types": "./dist/index.d.cts", | ||
| "exports": { | ||
| ".": { | ||
| "import": { | ||
| "types": "./dist/index.d.mts", | ||
| "default": "./dist/index.mjs" | ||
| }, | ||
| "require": { | ||
| "types": "./dist/index.d.cts", | ||
| "default": "./dist/index.cjs" | ||
| } | ||
| }, | ||
| "./package.json": "./package.json" | ||
| }, | ||
| "publishConfig": { | ||
| "access": "public", | ||
| "registry": "https://registry.npmjs.org/" | ||
| }, | ||
| "scripts": { | ||
| "build": "ts-bridge --project tsconfig.build.json --verbose --clean --no-references", | ||
| "build:all": "ts-bridge --project tsconfig.build.json --verbose --clean", | ||
| "build:docs": "typedoc", | ||
| "changelog:update": "../../scripts/update-changelog.sh @metamask/money-account-balance-service", | ||
| "changelog:validate": "../../scripts/validate-changelog.sh @metamask/money-account-balance-service", | ||
| "messenger-action-types:check": "tsx ../../packages/messenger-cli/src/cli.ts --check", | ||
| "messenger-action-types:generate": "tsx ../../packages/messenger-cli/src/cli.ts --generate", | ||
| "since-latest-release": "../../scripts/since-latest-release.sh", | ||
| "test": "NODE_OPTIONS=--experimental-vm-modules jest --reporters=jest-silent-reporter", | ||
| "test:clean": "NODE_OPTIONS=--experimental-vm-modules jest --clearCache", | ||
| "test:verbose": "NODE_OPTIONS=--experimental-vm-modules jest --verbose", | ||
| "test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --watch" | ||
| }, | ||
| "dependencies": { | ||
| "@ethersproject/contracts": "^5.7.0", | ||
| "@ethersproject/providers": "^5.7.0", | ||
| "@metamask/base-data-service": "^0.1.1", | ||
| "@metamask/controller-utils": "^11.20.0", | ||
| "@metamask/messenger": "^1.1.1", | ||
| "@metamask/metamask-eth-abis": "^3.1.1", | ||
| "@metamask/network-controller": "^30.0.1", | ||
| "@metamask/superstruct": "^3.1.0", | ||
| "@metamask/utils": "^11.9.0" | ||
| }, | ||
| "devDependencies": { | ||
| "@metamask/auto-changelog": "^6.0.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", | ||
| "typedoc-plugin-missing-exports": "^2.0.0", | ||
| "typescript": "~5.3.3" | ||
| }, | ||
| "engines": { | ||
| "node": "^18.18 || >=20" | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| import { Hex } from '@metamask/utils'; | ||
|
|
||
| export const VEDA_PERFORMANCE_API_BASE_URL = 'https://api.sevenseas.capital'; | ||
|
|
||
| export const VEDA_API_NETWORK_NAMES: Record<Hex, string> = { | ||
| '0xa4b1': 'arbitrum', | ||
| }; | ||
|
|
||
| export const DEFAULT_VEDA_API_NETWORK_NAME = VEDA_API_NETWORK_NAMES['0xa4b1']; | ||
|
|
||
| /** | ||
| * Minimal ABI for the Veda Accountant's `getRate()` function (selector 0x679aefce). | ||
| * Returns the exchange rate between vault shares (musdSHFvd) and the | ||
| * underlying asset (mUSD) as a uint256. | ||
| */ | ||
| export const ACCOUNTANT_ABI = [ | ||
| { | ||
| inputs: [], | ||
| name: 'getRate', | ||
| outputs: [{ internalType: 'uint256', name: 'rate', type: 'uint256' }], | ||
| stateMutability: 'view', | ||
| type: 'function', | ||
| }, | ||
| ] as const; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| export class VedaResponseValidationError extends Error { | ||
| constructor(message?: string) { | ||
| super(message ?? 'Malformed response received from Veda API'); | ||
| this.name = 'VedaResponseValidationError'; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| export { MoneyAccountBalanceService } from './money-account-balance-service'; | ||
| export type { | ||
| MoneyAccountBalanceServiceActions, | ||
| MoneyAccountBalanceServiceEvents, | ||
| MoneyAccountBalanceServiceMessenger, | ||
| } from './money-account-balance-service'; | ||
| export type { | ||
| MoneyAccountBalanceServiceGetMusdBalanceAction, | ||
| MoneyAccountBalanceServiceGetMusdSHFvdBalanceAction, | ||
| MoneyAccountBalanceServiceGetExchangeRateAction, | ||
| MoneyAccountBalanceServiceGetMusdEquivalentValueAction, | ||
| MoneyAccountBalanceServiceGetVaultApyAction, | ||
| } from './money-account-balance-service-method-action-types'; | ||
| export type { | ||
| ExchangeRateResponse, | ||
| MusdEquivalentValueResponse, | ||
| NormalizedVaultApyResponse, | ||
| } from './response.types'; | ||
78 changes: 78 additions & 0 deletions
78
...es/money-account-balance-service/src/money-account-balance-service-method-action-types.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| /** | ||
| * This file is auto generated. | ||
| * Do not edit manually. | ||
| */ | ||
|
|
||
| import type { MoneyAccountBalanceService } from './money-account-balance-service'; | ||
|
|
||
| /** | ||
| * Fetches the mUSD ERC-20 balance for the given account address via RPC. | ||
| * | ||
| * @param accountAddress - The Money account's Ethereum address. | ||
| * @returns The mUSD balance as a raw uint256 string. | ||
| */ | ||
| export type MoneyAccountBalanceServiceGetMusdBalanceAction = { | ||
| type: `MoneyAccountBalanceService:getMusdBalance`; | ||
| handler: MoneyAccountBalanceService['getMusdBalance']; | ||
| }; | ||
|
|
||
| /** | ||
| * Fetches the musdSHFvd (Veda vault share) ERC-20 balance for the given | ||
| * account address via RPC. | ||
| * | ||
| * @param accountAddress - The Money account's Ethereum address. | ||
| * @returns The musdSHFvd balance as a raw uint256 string. | ||
| */ | ||
| export type MoneyAccountBalanceServiceGetMusdSHFvdBalanceAction = { | ||
| type: `MoneyAccountBalanceService:getMusdSHFvdBalance`; | ||
| handler: MoneyAccountBalanceService['getMusdSHFvdBalance']; | ||
| }; | ||
|
|
||
| /** | ||
| * Fetches the current exchange rate from the Veda Accountant contract via | ||
| * RPC. The rate represents the conversion factor from musdSHFvd shares to | ||
| * the underlying mUSD asset. | ||
| * | ||
| * @param options - The options for the query. | ||
| * @param options.staleTime - The stale time for the query. Defaults to 30 seconds. | ||
| * @returns The exchange rate as a raw uint256 string. | ||
| */ | ||
| export type MoneyAccountBalanceServiceGetExchangeRateAction = { | ||
| type: `MoneyAccountBalanceService:getExchangeRate`; | ||
| handler: MoneyAccountBalanceService['getExchangeRate']; | ||
| }; | ||
|
|
||
| /** | ||
| * Computes the mUSD-equivalent value of the account's musdSHFvd holdings. | ||
| * Internally fetches the musdSHFvd balance and exchange rate (using cached | ||
| * values when available within their staleTime windows), then multiplies | ||
| * them. | ||
| * | ||
| * @param accountAddress - The Money account's Ethereum address. | ||
| * @returns The musdSHFvd balance, exchange rate, and computed | ||
| * mUSD-equivalent value as raw uint256 strings. | ||
| */ | ||
| export type MoneyAccountBalanceServiceGetMusdEquivalentValueAction = { | ||
| type: `MoneyAccountBalanceService:getMusdEquivalentValue`; | ||
| handler: MoneyAccountBalanceService['getMusdEquivalentValue']; | ||
| }; | ||
|
|
||
| /** | ||
| * Fetches the vault's APY and fee breakdown from the Veda performance REST API. | ||
| * | ||
| * @returns The normalized vault APY response. | ||
| */ | ||
| export type MoneyAccountBalanceServiceGetVaultApyAction = { | ||
| type: `MoneyAccountBalanceService:getVaultApy`; | ||
| handler: MoneyAccountBalanceService['getVaultApy']; | ||
| }; | ||
|
|
||
| /** | ||
| * Union of all MoneyAccountBalanceService action types. | ||
| */ | ||
| export type MoneyAccountBalanceServiceMethodActions = | ||
| | MoneyAccountBalanceServiceGetMusdBalanceAction | ||
| | MoneyAccountBalanceServiceGetMusdSHFvdBalanceAction | ||
| | MoneyAccountBalanceServiceGetExchangeRateAction | ||
| | MoneyAccountBalanceServiceGetMusdEquivalentValueAction | ||
| | MoneyAccountBalanceServiceGetVaultApyAction; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.